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中文网其它相关文章!
已抢16607个
抢已抢49554个
抢已抢16893个
抢已抢8996个
抢已抢4590个
抢已抢4608个
抢