uniapp小程序,实现每次进入页面时自动开启 30 秒的倒计时。


<view class="number">{{count}}</view> 
<!-- 倒计时数字 -->
data() {
    return {
      count: 30,
      timer: null,
    };
},
methods: {
	  countDown() {
      	let _this = this;
      	const TIME_COUNT = 30;
      	if (!this.timer) {
        	this.count = TIME_COUNT;
       		this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--;
        } else {
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000);
      }
    },
},
onShow() {
    this.countDown();
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM