zoukankan      html  css  js  c++  java
  • Vue练习二十七:03_09_倒计时时钟

    Demo 在线地址:
    https://sx00xs.github.io/test/27/index.html
    ---------------------------------------------------------------
    ide: vscode
    文件格式:.vue
    解析:(待补)

    <template>
      <div id="app">
        <div class="countdown">
          <span>{{spanVal1}}</span>分钟<span>{{spanVal2}}</span><input :class="{cancel:isCancel}" type="button" value=""
          @click="handleClick"
          >
        </div>
      </div>
    </template>
    <script>
    function format(a){
      return a.toString().replace(/^(d)$/,'0$1')
    }
    export default {
      data:function(){
        return{
          isCancel:false,
          spanVal1:'01',
          spanVal2:'40',
          timer:null
        }
      },
      methods:{
        handleClick(){
          !this.isCancel ? (this.timer=setInterval(this.updateTime,1000),this.updateTime()) : (clearInterval(this.timer));
          !this.isCancel ? this.isCancel=true : this.isCancel=false;
        },
        updateTime(){
          var Remain=this.spanVal1.replace(/^0/,'') * 60 + parseInt(this.spanVal2.replace(/^0/,''));
          if(Remain <= 0){
            clearInterval(this.timer);
            return;
          }
          Remain--;
          this.spanVal1=format(parseInt(Remain/60));
          Remain %= 60;
          this.spanVal2=format(parseInt(Remain));
        }
      }
    }
    </script>
  • 相关阅读:
    Linux終端一行命令发送邮件
    团队冲刺2.4
    团队冲刺2.3
    团队冲刺2.2
    找水王
    评价win10自带输入法——微软拼音输入法
    梦断代码阅读笔记01
    团队冲刺2.1
    第十三周总结
    第十二周总结
  • 原文地址:https://www.cnblogs.com/sx00xs/p/11266126.html
Copyright © 2011-2022 走看看