这篇文章主要为大家详细介绍了vue中轮训器的使用,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
代码如下:
<template>
<div >
{{log}}
</div>
</template>
<script>
export default {
name: "TrainingInRotation",
data(){
return {
log:0,
timerId:1, // 模拟计时器id,唯一性
timerObj :{}, // 计时器存储器
}
},
created(){
this.startTraining();
},
methods: {
/*
* 开始轮训
* */
startTraining() {
let this_ = this;
const id = this.timerId++
this.timerObj[id] = true
async function timerFn() {
if (!this_.timerObj[id]) return
await this_.getData();
setTimeout(timerFn, 1 * 1000)
}
timerFn();
},
/*
* 停止轮训
* */
stopTime() {
this.timerObj = {}
},
/*
* 要轮训的代码
* */
getData(){
this.log+=1;
console.log("this.log:"+this.log);
}
},
destroyed(){
this.stopTime();
}
}
</script>
<style scoped>
</style>
【图片暂缺】
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对四海网的支持。如果你想了解更多相关内容请查看下面相关链接
本文来自:http://www.q1010.com/184/6990-0.html
注:关于vue中轮训器的使用的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:vue.js
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。