<!-- 可以点击 -->
<button type="warning" v-if="isGetCode" class="getCode" style="width:40%" round @click="getSendPhoneMessage" size="mini" id="getcode">获取验证码</button>
<!-- 不可以 -->
<button type="warning" v-else class="getCode grey" style="width:40%" round size="mini" id="getcode">{{time}}秒后可重新获取</button>
初始设置:
token: "",
isGetCode: true, // 是否点击了获取code
time: 60,
getSendPhoneMessage(){
var clock = "";
var nums = 60;
this.time = nums;
clock = setInterval(() => {
nums--;
if (nums > 0) {
this.time = nums + "秒后可重新获取";
} else {
clearInterval(clock); //清除js定时器
this.isGetCode = true;
this.time = "点击发送验证码";
nums = 60; //重置时间
}
}, 1000); //一秒执行一次
}