vue中輪訓器的使用
更新時間:2019年01月27日 11:27:02 作者:Moment°回憶
今天小編就為大家分享一篇關于vue中輪訓器的使用,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
核心代碼:
<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>
效果圖:

總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內(nèi)容請查看下面相關鏈接
相關文章
vue elementui el-form rules動態(tài)驗證的實例代碼詳解
在使用elementUI el-form 中,對于業(yè)務不同的時候可能會產(chǎn)生不同表單結構,但是都是存在同一個表單控件el-form中。這篇文章主要介紹了vue elementui el-form rules動態(tài)驗證的實例代碼,需要的朋友可以參考下2019-05-05

