vue中輪訓(xùn)器的使用
更新時間:2019年01月27日 11:27:02 作者:Moment°回憶
今天小編就為大家分享一篇關(guān)于vue中輪訓(xùn)器的使用,小編覺得內(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: {
/*
* 開始輪訓(xùn)
* */
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();
},
/*
* 停止輪訓(xùn)
* */
stopTime() {
this.timerObj = {}
},
/*
* 要輪訓(xùn)的代碼
* */
getData(){
this.log+=1;
console.log("this.log:"+this.log);
}
},
destroyed(){
this.stopTime();
}
}
</script>
<style scoped>
</style>
效果圖:

總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
vue elementui el-form rules動態(tài)驗證的實例代碼詳解
在使用elementUI el-form 中,對于業(yè)務(wù)不同的時候可能會產(chǎn)生不同表單結(jié)構(gòu),但是都是存在同一個表單控件el-form中。這篇文章主要介紹了vue elementui el-form rules動態(tài)驗證的實例代碼,需要的朋友可以參考下2019-05-05
一文詳解Vue的響應(yīng)式原則與雙向數(shù)據(jù)綁定
使用 Vue.js 久了,還是不明白響應(yīng)式原理和雙向數(shù)據(jù)綁定的區(qū)別?今天,我們就一起來學(xué)習(xí)一下,將解釋它們的區(qū)別,快跟隨小編一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08

