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-cli 引入jQuery,Bootstrap,popper的方法
這篇文章主要介紹了vue-cli 引入jQuery,Bootstrap,popper的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09詳解Vue學(xué)習(xí)筆記進(jìn)階篇之列表過渡及其他
本篇文章主要介紹了詳解Vue學(xué)習(xí)筆記進(jìn)階篇之列表過渡及其他,具有一定的參考價值,有興趣的可以了解一下2017-07-07