wya1

飞道的博客

app前端验证码60秒倒计时(全部代码)

411人阅读  评论(0)

直接上代码,

<view>
				<input type="text" v-model="code" value="" placeholder="请填写验证码"  />
				<button v-if="showText" type="button" @click="getCode()" >获取验证码</button>
				<button v-else  type="button" >{{second}}s重新发送</button>
</view>
data() {
				return {
					code:"",//验证码
					second:60,//默认60秒
					showText:true,//判断是否发送
				};
			},
getCode(){
					var that = this;
					var interval = setInterval(() => {
					    var times = that.second-1;
					    //that.second = times<10?'0'+times:times ;//小于10秒补 0
						that.second = times
					}, 1000)
					setTimeout(() => {
					    clearInterval(interval)
					    that.second=60
					    that.showText = true
					}, 60000);
					uni.request({
					......//此处省略
						success :function(res) {
							that.showText = false
							}
					})
				}

转载:https://blog.csdn.net/Java_zxhao/article/details/106091026
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场