HTML:
<p id="example"> <button @click="send"> <span v-if="sendMsgDisabled">{{time+'秒后获取'}}</span> <span v-if="!sendMsgDisabled">send</span> </button> </p>
JS:
var vm = new Vue({ el: '#example', 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); } } })
以上是制作一个基于vue的倒计时demo 的详细内容。更多信息请关注PHP中文网其他相关文章!