vue倒计时

该博客转自网络并做简单修改,主要涉及前端的template、script和css相关内容,方便后续取用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

声明:此篇文章转自https://www.jb51.net/article/138555.htm,有过简单修改,便于以后自己需要时直接拿

template

<p :class="['getcode',!canClick?'getcodeing':'']" @click="getCode()">{{content}}</p>

script

data() {
    return {
		// 获取验证码相关
		content: '发送验证码',	//按钮显示内容
		totalTime: 10,		    //记录具体倒计时时间
		canClick: true,		    //是否可以点击(在倒计时过程中不可点击)
    };
},

methods:{
    // 点击获取验证码
    getCode() {
		this.content = this.totalTime + 's后重新发送' //这里解决60秒不见了的问题
		if(!this.canClick) return;					//默认true,若为false,不可点击,跳出循环
		this.canClick = false						//使其不可点击
		let clock = window.setInterval(() => {
			this.totalTime--
			this.content = this.totalTime + 's后重新发送'
			if (this.totalTime < 0) {     			//当倒计时小于0时清除定时器
				window.clearInterval(clock)
				this.content = '重新发送验证码'
				this.totalTime = 10
				this.canClick = true				//倒计时结束,使其可点击
			}
		},1000)
    },
}

css


.getcode{
	font-size: 0.24rem;
	color: #55ABEB;
	background: #DFEEFA;
	padding: 0.12rem 0.15rem;
	margin-top: -0.2rem;
	border-radius: 2rem;
	float: right;
}
.getcodeing{
	color: #9B9B9B;;
	background: #F2F2F2;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值