uniapp实现弹框确认倒计时功能

效果图:

这里为了更好实现功能,以及保证样式自然的情况下,借助了uview里的modal模态框 

代码如下: 

一个按钮点击事件触发弹框,通过插槽传入自定义确认按钮 

<button class="button" @click="topay">按钮</button>
<u-modal v-model="modalShow" :show-cancel-button="true" :content="modalContent">
	<!-- 自定义确认按钮 -->
	<template v-slot:confirm-button>
		<button class="confirmBtn" :disabled="countdown > 0" @click="confirmAction">{{countdown > 0 ? `${countdown}秒` : '确认'}}</button>
	</template>

</u-modal>

data声明:

data() {
			return {
				//弹框
				modalShow: false,
				modalContent: '您确定进行操作吗?',
				countdown: 0, // 初始倒计时时间
				timer: null, // 计时器
			}
		},

倒计时代码: 

// 倒计时
time() {
	this.countdown = 3;
	this.timer = setInterval(() => {
	    if (this.countdown > 0) {
			this.countdown -= 1;
	    } else {
			clearInterval(this.timer);
			this.timer = null;
	    }
    }, 1000);
},

触发弹框以及点击确认之后的代码: 

topay() {
	this.modalShow = true
    //在这边也可以给modalContent赋值传值,修改为动态的文本都可以
	this.time()
},

confirmAction() {
   //点击确认之后触发
}

自定义确认按钮css样式

/deep/.confirmBtn {
	height: 52px;
	line-height: 52px;
	background-color: #fff;
	border: none !important;
	color: #2979ff;
}
	
/deep/.confirmBtn::after {
	border: none !important;
}

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值