Home  >  Article  >  Web Front-end  >  Make a countdown demo based on vue

Make a countdown demo based on vue

一个新手
一个新手Original
2017-10-11 10:29:392121browse

HTML:

 <p id="example">
    <button @click="send">
      <span v-if="sendMsgDisabled">{{time+&#39;秒后获取&#39;}}</span>
      <span v-if="!sendMsgDisabled">send</span>
    </button>
  </p>

JS:

var vm = new Vue({
    el: &#39;#example&#39;,
    data() {      return {
        time: 60, // 发送验证码倒计时
        sendMsgDisabled: false
      }
    },
    methods: {
      send() {        let me = this;
        me.sendMsgDisabled = true;        
        let interval = window.setInterval(function() {
          if ((me.time--) <= 0) {
            me.time = 60;
            me.sendMsgDisabled = false;
            window.clearInterval(interval); //停止
          }
        }, 1000);
      }
    }
  })

The above is the detailed content of Make a countdown demo based on vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn