<template class="bgdiv-content-view">
<div
class="toolbar-one"
style="height: 30px;margin-top: 5px;">
<el-switch
v-model="kicktest"
active-text="开启"
inactive-text="关闭"/>
</div>
</template>
data() {
return {
kicktest: false, // 随机测试全局变量
}
}
watch: {
kicktest(val) { //检测
if (val) {
console.log('开启')
console.log(val)
this.stratTest()
} else {
console.log('关闭定时任务')
console.log(val)
clearInterval(this.testRandomKickId)
}
}
}
methods: {
stratTest() {
console.log('开启定时任务')
var self = this
self.testRandomKickId = setInterval(doRefreshRandomKick, 2000) // 定时器刷新
function doRefreshRandomKick() {
console.log('随机t人')
}
}
}
效果: