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

使用vue實現(xiàn)計時器功能

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

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

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

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

<script>  
//定時器 異步運行  
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í)行,代碼如下:

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

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

計時器

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, // 秒的計數(shù)
  cde : 0, // 分的計數(shù)
  efg : 0, // 時的計數(shù)
   }
  },
  props: {
    msg: String
  },
  mounted() {
   
  },
  methods:{
  // 開始計時
 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)
 },
 // 暫停計時
 endHandler(){
  this.flag = clearInterval(this.flag)
 }
  }
}
</script>

效果如下:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

开平市| 汪清县| 石景山区| 巫溪县| 财经| 称多县| 敦煌市| 巴塘县| 南岸区| 栖霞市| 瑞安市| 新余市| 长宁区| 南和县| 镇雄县| 淳安县| 乌海市| 壤塘县| 凉城县| 宣汉县| 万安县| 稷山县| 红安县| 九龙城区| 屏山县| 东丰县| 牟定县| 夏邑县| 和政县| 云和县| 平江县| 碌曲县| 阜阳市| 河池市| 左云县| 郴州市| 旬阳县| 法库县| 枣庄市| 蓬莱市| 张家界市|