uniapp 微信小程序点击开始倒计时

一、示例

当点击按钮时就开始倒计时

代码

bash 复制代码
<template>
  <view class="sq_box">
    <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>
  </view>
</template>

<script>
  export default {
    name: 'GeneratePoster',
    data() {
      return {
        //弹框
        				modalShow: false,
        				modalContent: '您确定进行操作吗?',
        				countdown: 0, // 初始倒计时时间
        				timer: null, // 计时器
      };
    },
    onLoad(option) {
    },

    methods: {
      // 倒计时
      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() {
         //点击确认之后触发
      }
    }
  };
</script>

<style lang="scss">
.confirmBtn{
  height: 52px;
  line-height: 52px;
  background-color: #fff;
  border: none !important;
  color: #2979ff;
}
  	
  .confirmBtn{
      border: none !important;
    }
</style>
相关推荐
千寻技术帮18 小时前
50055_基于AI的互帮互助小程序(源码+文档+数据库脚本+部署教程)
数据库·人工智能·小程序·毕业设计·springboot·课程设计
千寻技术帮19 小时前
微信小程序血压管理系统设计与实现_50054(Spring Boot + Vue + MySQL)
spring boot·小程序·vue·毕业设计·课程设计·血压助手
用户788477316342 天前
小程序提审被拒 7 次复盘:审核备注怎么写、隐私接口怎么声明
微信小程序
李纲明2 天前
微信小程序点餐加料靠自由备注错做或漏做:先核选项组与必选校验,再查厨打标签与冲突拦截
微信小程序·devdiy·点餐加料·自由备注·选项组·必选校验·厨打标签
FX1317887KP_3 天前
KPF口语高频动词短语清单,搭配AI口语陪练工具,练熟练透
小程序·ket口语·pet口语·fce备考·剑桥英语
拖孩3 天前
# 我又用 AI 做了个小程序:24 天,记录我这辈子认识的人
前端·后端·微信小程序
李纲明3 天前
微信小程序选片一拖几个月或口头加片扯皮:先核截止日与节点提醒,再查加项确认与尾款
微信小程序·devdiy·选片截止·节点提醒·加项确认·尾款交付·摄影出片
微订校园外卖系统3 天前
自己做校园外卖跑腿小程序用什么系统:多商户与单店架构
小程序·架构·外卖系统·本地生活·微订
2401_878851014 天前
微信小程序实战:掌握“手机状态”感知与设备 API 全解析
智能手机·微信小程序·notepad++
wuxianda10304 天前
uniapp 与跨端打包项目:壳子和框架层默认特征,相似是从哪里来的
uni-app