Skip to content

Commit 4fe1eda

Browse files
committed
添加cleartimeout,修复快速props的时候的产生的错误
1 parent e406ff4 commit 4fe1eda

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

__test__/index.test.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,21 @@ describe('NuDialog开关问题', () => {
119119
},16)
120120
})
121121
})
122-
// it('用户快速快关,有bug',async ()=>{
123-
// const wrapper = mount(NuDialog)
124-
// wrapper.setProps({open:true})
125-
// wrapper.setProps({open:false})
126-
// await new Promise((rs,rj)=>{
127-
// setTimeout(()=>{
128-
// console.log(wrapper.vm.show,wrapper.vm.render)
129-
// rs()
130-
// },300)
131-
// })
132-
// })
122+
it('用户快速快关',async ()=>{
123+
const wrapper = mount(NuDialog)
124+
wrapper.setProps({open:true})
125+
wrapper.setProps({open:false})
126+
wrapper.setProps({open:true})
127+
wrapper.setProps({open:true})
128+
wrapper.setProps({open:false})
129+
await new Promise((rs,rj)=>{
130+
setTimeout(()=>{
131+
expect(wrapper.vm.show).toEqual(false)
132+
expect(wrapper.vm.render).toEqual(false)
133+
rs()
134+
},300)
135+
})
136+
})
133137
})
134138

135139
describe('beforeClose api',()=>{

src/index.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
data() {
2323
return {
2424
show: false,
25-
render: this.open
25+
render: this.open,
26+
timecount:null
2627
}
2728
},
2829
props: {
@@ -73,18 +74,20 @@
7374
},
7475
methods: {
7576
handleOpen() {
77+
clearTimeout(this.timecount)
7678
this.render = true;
7779
document.body.appendChild(this.$el);
7880
// 动画的时间
79-
setTimeout(() => {
81+
this.timecount=setTimeout(() => {
8082
this.show = true;
8183
}, 16);
8284
document.body.classList.add('nu_dialog_open');
8385
},
8486
dialogClose() {
87+
clearTimeout(this.timecount)
8588
this.show = false;
8689
// 动画的时间
87-
setTimeout(() => {
90+
this.timecount=setTimeout(() => {
8891
this.render = false;
8992
}, this.speed);
9093
document.body.classList.remove('nu_dialog_open');

0 commit comments

Comments
 (0)