最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用vue實(shí)現(xiàn)計(jì)時器功能

 更新時間:2021年08月06日 11:39:31   作者:rock_23  
這篇文章主要為大家詳細(xì)介紹了使用vue實(shí)現(xiàn)計(jì)時器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)計(jì)時器功能的具體代碼,供大家參考,具體內(nèi)容如下

首先我們要知道setTimeout和setInterval的區(qū)別

setTimeout只在指定時間后執(zhí)行一次,代碼如下:

<script>  
//定時器 異步運(yùn)行  
function hello(){  
alert("hello");  
}  
//使用方法名字執(zhí)行方法  
var t1 = window.setTimeout(hello,1000);  
var t2 = window.setTimeout("hello()",3000);//使用字符串執(zhí)行方法  
window.clearTimeout(t1);//去掉定時器  
</script>

setInterval以指定時間為周期循環(huán)執(zhí)行,代碼如下:

//實(shí)時刷新時間單位為毫秒  
setInterval('refreshQuery()',8000);   
/* 刷新查詢 */  
function refreshQuery(){  
   $("#mainTable").datagrid('reload',null);  
}

一般情況下setTimeout用于延遲執(zhí)行某方法或功能,
setInterval則一般用于刷新表單,對于一些表單的實(shí)時指定時間刷新同步

計(jì)時器

HTML代碼

<div class="father">
  <ul>
   <li>{{one}}<span>:</span></li>
   <li>{{two}}<span>:</span></li>
   <li>{{three}}</li>
  </ul>
  <el-button type="primary" @click="startHandler">開始</el-button>
  <el-button type="primary" @click="endHandler">暫停</el-button>
</div>

JAVASCRIPT代碼

<script>
export default {
  name: 'HelloWorld',
  data(){
   return {
  flag: null,
  one : '00', // 時
  two : '00', // 分
  three : '00', // 秒
  abc : 0, // 秒的計(jì)數(shù)
  cde : 0, // 分的計(jì)數(shù)
  efg : 0, // 時的計(jì)數(shù)
   }
  },
  props: {
    msg: String
  },
  mounted() {
   
  },
  methods:{
  // 開始計(jì)時
 startHandler(){
  this.flag = setInterval(()=>{
   if(this.three === 60 || this.three === '60'){
    this.three = '00';
    this.abc = 0;
    if(this.two === 60 || this.two === '60'){
     this.two = '00';
     this.cde = 0;
     if(this.efg+1 <= 9){
      this.efg++;
      this.one = '0' + this.efg;
     }else{
      this.efg++;
      this.one = this.efg;
     }
    }else{
     if(this.cde+1 <= 9){
      this.cde++;
      this.two = '0' + this.cde;
     }else{
      this.cde++;
      this.two = this.cde;
     }
    }
   }else{
    if(this.abc+1 <= 9){
     this.abc++;
     this.three = '0' + this.abc;
    }else{
     this.abc++;
     this.three=this.abc;
    }
   }
   
  },100)
 },
 // 暫停計(jì)時
 endHandler(){
  this.flag = clearInterval(this.flag)
 }
  }
}
</script>

效果如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

定南县| 新营市| 芦山县| 乌什县| 健康| 德阳市| 塔城市| 石柱| 阿尔山市| 丹寨县| 黎川县| 方正县| 呼伦贝尔市| 林口县| 天镇县| 塔城市| 芜湖县| 湖州市| 盐亭县| 呼和浩特市| 曲周县| 定边县| 类乌齐县| 辉南县| 东阳市| 始兴县| 东山县| 双桥区| 张掖市| 阿荣旗| 四子王旗| 开封市| 房产| 获嘉县| 罗田县| 邵阳县| 屏东县| 北海市| 万山特区| 麻阳| 霞浦县|