This time I will bring you vue to implement SMS Verification codeCountdown, vue to implement SMS verification code countdownWhat are the precautions, the following is a practical case, let's take a look.
There are two span tags wrapped in the button. Different spans are displayed according to the click status . The key code is the countdown:
<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); } } })
The above is the detailed content of Vue implements SMS verification code countdown. For more information, please follow other related articles on the PHP Chinese website!