import {mixin as VueTimers} from 'vue-timers'
export default {
mixins: [VueTimers], // 混入
timers: {
tm1: {
time: 300, // 定时时间
repeat: true, // 是否重复执行
immediate: false // 是否立即执行
},
tm2: {
time: 1000, // 定时时间
repeat: false, // 是否重复执行
immediate: true // 是否立即执行
}
},
methods: {
tm1 () {
// 要执行的内容写在这里
.....
if (满足条件) {
this.$timer.stop('tm1') // 结束并销毁tm1
}
},
tm2 () {
// 要执行的内容写在这里
.....
this.$timer.stop('tm1') // 结束并销毁tm1
},
触发函数 () {
this.$timer.start('tm1') // 触发执行
this.$timer.start('tm2') // 触发执行
}
}
}
// this.$timer.start('tm1') 触发执行
// this.$timer.stop('tm1') 结束销毁
(前端vue) vue-timers 替代定时器和延时器
最新推荐文章于 2025-01-16 11:49:51 发布