2***@qq.com
2***@qq.com
  • 发布:2019-01-02 21:15
  • 更新:2020-06-08 17:04
  • 阅读:8154

uniapp怎么设置按钮,按一次过一段时间才能在按呀。类似发送验证码按钮

分类:uni-app

这是我的button : <button type="primary" class="butto" @tap="SMS"> 发送验证码 </button>

2019-01-02 21:15 负责人:无 分享
已邀请:
tatc

tatc - 不知道说什么好

设置一个变量然后让那个变量计数
data(){
return{
timer:60
}
}
,methods:{
SMS(){
let timer1 = setInterval(() => {
this.timer--;
if (this.timer == -1) {
clearInterval(timer1);
this.timer = 60;
}
}, 1000);
}
}

2***@qq.com

2***@qq.com (作者) - 90后学生

<button type="primary" class="butto" :disabled="disabled" @tap="SMS"> {{title}} </button>

data(){
return {
timer:60,
disabled: false,
title:'发送验证码'
}
},
methods: {
//single message send
SMS: function (e) {
if(this.account.length<11){
uni.showToast({
title: '手机号不符合要求',
duration: 2000,
icon:'none'
});
return;
}
else{
this.disabled=true
let timer1 = setInterval(() => {
this.timer--;
this.title='请等待'+this.timer+'秒后再次发送'
if (this.timer == 0) {
clearInterval(timer1);
this.timer = 60;
this.disabled=false
this.title='发送验证码'
return;
}
}, 1000);
}
}

大概解决了这个问题了。

1***@qq.com

1***@qq.com

disabled 设置任意值。button都不可点击 是什么鬼

  • 未尛2333

    要用数据绑定的形式给true/false :disabled="dis"


    2019-04-25 11:08

丝路网

丝路网

你这个代码点击获取开始倒计时后,马上切换别的页面,再回来就立刻又可以点击获取验证码了。

那这个倒计时还有什么意义?

S1ow

S1ow

自定义指令他不香吗

该问题目前已经被锁定, 无法添加新回复