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>
相关推荐
qq_12498707531 小时前
基于springboot健康养老APP的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·mysql·微信小程序·毕业设计
汤姆yu1 小时前
基于微信小程序的驾校预约与学习系统
学习·小程序·驾校预约
夏源2 小时前
【微信小程序】实现引入 Echarts 并实现更新数据
微信小程序
speedoooo2 小时前
未来的App不再需要菜单栏?
前端·ui·容器·小程序·web app
猿究院_xyz3 小时前
微信小程序与echarts联动安卓真机测试出现黑色阴影
前端·javascript·微信小程序·小程序·echarts
说私域4 小时前
不同类型企业构建私域流量的必要性及定制开发AI智能名片商城小程序的应用
大数据·人工智能·小程序
雯0609~5 小时前
uni-app:防止重复提交
前端·javascript·uni-app
老华带你飞5 小时前
健身房预约|基于springboot 健身房预约小程序系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·小程序
2501_915909065 小时前
苹果应用加密方案的一种方法,在没有源码的前提下,如何处理 IPA 的安全问题
android·安全·ios·小程序·uni-app·iphone·webview
百锦再5 小时前
与AI沟通的正确方式——AI提示词:原理、策略与精通之道
android·java·开发语言·人工智能·python·ui·uni-app