feat(CountDown): add change event (#5599)

This commit is contained in:
陈嘉涵 2020-01-23 10:22:15 +08:00
parent b83bed3b6c
commit 1404c82dba
4 changed files with 21 additions and 0 deletions

View File

@ -130,6 +130,7 @@ export default {
| Event | Description | Arguments |
|------|------|------|
| finish | Triggered when count down finished | - |
| change `2.4.4` | Triggered when count down changed | timeData |
### Slots

View File

@ -140,6 +140,7 @@ export default {
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| finish | 倒计时结束时触发 | - |
| change `2.4.4` | 倒计时变化时触发 | timeData |
### Slots

View File

@ -141,6 +141,7 @@ export default createComponent({
setRemain(remain) {
this.remain = remain;
this.$emit('change', this.timeData);
if (remain === 0) {
this.pause();

View File

@ -213,3 +213,21 @@ test('pause when deactivated', async () => {
wrapper.setData({ render: true });
expect(countDown.counting).toBeFalsy();
});
test('change event', async () => {
const wrapper = mount(CountDown, {
propsData: {
time: 1,
},
});
expect(wrapper.emitted('change')).toBeFalsy();
await later(50);
expect(wrapper.emitted('change')[0][0]).toEqual({
days: 0,
hours: 0,
milliseconds: 0,
minutes: 0,
seconds: 0,
});
});