时间:2021-07-01 10:21:17 帮助过:2人阅读
button里面包两个span标签,根据点击状态,显示不同的span,关键代码就是倒计时:
<p id="example"> <button @click="send"> <span v-if="sendMsgDisabled">{{time+'秒后获取'}}</span> <span v-if="!sendMsgDisabled">send</span> </button> </p>
button { width: 100px; height: 50px background: pink; }
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); } } })
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
以上就是vue实现短信验证码倒计时的详细内容,更多请关注Gxl网其它相关文章!