mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 15:09:16 +08:00
parent
633b835e01
commit
5c39921742
@ -77,11 +77,6 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
currentValue(val) {
|
|
||||||
this.$emit('input', val);
|
|
||||||
this.$emit('change', val);
|
|
||||||
},
|
|
||||||
|
|
||||||
value(val) {
|
value(val) {
|
||||||
val = this.correctValue(+val);
|
val = this.correctValue(+val);
|
||||||
if (val !== this.currentValue) {
|
if (val !== this.currentValue) {
|
||||||
@ -105,6 +100,7 @@ export default create({
|
|||||||
onInput(event) {
|
onInput(event) {
|
||||||
const val = +event.target.value;
|
const val = +event.target.value;
|
||||||
this.currentValue = this.correctValue(val);
|
this.currentValue = this.correctValue(val);
|
||||||
|
this.emitInput();
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(type) {
|
onChange(type) {
|
||||||
@ -116,7 +112,13 @@ export default create({
|
|||||||
const step = +this.step;
|
const step = +this.step;
|
||||||
const currentValue = +this.currentValue;
|
const currentValue = +this.currentValue;
|
||||||
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
||||||
|
this.emitInput();
|
||||||
this.$emit(type);
|
this.$emit(type);
|
||||||
|
},
|
||||||
|
|
||||||
|
emitInput() {
|
||||||
|
this.$emit('input', this.currentValue);
|
||||||
|
this.$emit('change', this.currentValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -79,13 +79,11 @@ describe('Stepper', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-stepper')).to.be.true;
|
expect(wrapper.hasClass('van-stepper')).to.be.true;
|
||||||
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
|
||||||
|
|
||||||
wrapper.vm.value = 2;
|
wrapper.vm.value = 2;
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
wrapper.vm.$nextTick(() => {
|
wrapper.vm.$nextTick(() => {
|
||||||
expect(eventStub.calledWith('input'));
|
expect(wrapper.vm.currentValue).to.equal(2);
|
||||||
expect(eventStub.calledWith('change'));
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -135,4 +133,20 @@ describe('Stepper', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not fire any event on props changed', (done) => {
|
||||||
|
wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
|
||||||
|
wrapper.vm.value = 2;
|
||||||
|
wrapper.update();
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(eventStub.called).to.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user