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

這里做的是點(diǎn)擊按鈕開(kāi)始與結(jié)束倒計(jì)時(shí)的功能
<div v-if='rptType'>{{str}}</div><div : @click='receipt'>開(kāi)始</div>
data(){ return{ rptType: false,//狀態(tài) h:0,//定義時(shí),分,秒,毫秒并初始化為0;m:0,ms:0,s:0,time:0,str:’’, }},mounted:function(){ this.$nextTick(function () {//整個(gè)視圖都渲染完畢 })},methods:{ getTask: function(e){ this.taskType = e; }, //開(kāi)始 receipt: function() { this.rptType = !this.rptType; if(this.rptType){ this.time=setInterval(this.timer,50); }else{ this.reset() } }, timer: function(){ //定義計(jì)時(shí)函數(shù) this.ms=this.ms+50; //毫秒 if(this.ms>=1000){ this.ms=0; this.s=this.s+1; //秒 } if(this.s>=60){ this.s=0; this.m=this.m+1;//分鐘 } if(this.m>=60){ this.m=0; this.h=this.h+1;//小時(shí) } this.str =this.toDub(this.h)+':'+this.toDub(this.m)+':'+this.toDub(this.s)+''/*+this.toDubms(this.ms)+'毫秒'*/; // document.getElementById(’mytime’).innerHTML=h+'時(shí)'+m+'分'+s+'秒'+ms+'毫秒'; }, toDub: function(n){ //補(bǔ)0操作 if(n<10){ return '0'+n; } else { return ''+n; } }, reset: function(){ //重置 clearInterval(this.time); this.h=0; this.m=0; this.ms=0; this.s=0; this.str='00:00:00'; },}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算2. Spring如何集成ibatis項(xiàng)目并實(shí)現(xiàn)dao層基類(lèi)封裝3. JS圖片懶加載庫(kù)VueLazyLoad詳解4. IDEA 2020.1.2 安裝教程附破解教程詳解5. Python 解決火狐瀏覽器不彈出下載框直接下載的問(wèn)題6. Java利用TCP協(xié)議實(shí)現(xiàn)客戶(hù)端與服務(wù)器通信(附通信源碼)7. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶(hù)登錄的步驟8. Java實(shí)現(xiàn)的迷宮游戲9. Java PreparedStatement用法詳解10. django queryset相加和篩選教程

網(wǎng)公網(wǎng)安備