Home > Web Front-end > JS Tutorial > body text

Make a countdown demo based on vue

一个新手
Release: 2017-10-11 10:29:39
Original
2072 people have browsed it

HTML:

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

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);
      }
    }
  })
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!