let demo = new Vue({
el: '#app',
data: {
msg: '我是跑马灯',
timer: null,
},
methods: {
start: function () {
if (this.timer) {
return;
}
this.timer = setInterval(() => {
let start = this.msg.substring(0, 1);
let end = this.msg.substring(1);
this.msg = end + start;
}, 500)
},
end: function () {
//清除定时器后将timer置为0来叠加
clearInterval(this.timer);
this.timer = null;
}
}
});
解决定时器叠加问题
猜你喜欢
转载自blog.csdn.net/qq_43137725/article/details/103589046
今日推荐
周排行