uniapp实现发送验证码倒计时效果
<button type="primary" @click='getVerificationCode' :disabled='disabled'>{{btntxt}}</button>
<script> import Vue from 'vue'; export default Vue.extend({ data() { return { btntxt: '发送验证码', seconds: 60, disabled: false, } }, methods: { getVerificationCode() { const timer = setInterval(() => { this.btntxt = this.seconds + '秒再试'; this.seconds--; this.disabled = true; if(this.seconds === 0){ clearInterval(timer); this.btntxt = '发送验证码'; this.seconds = 60; this.disabled = false } }, 1000); } }, }); </script>
再忙也别忘记学习