uniapp实现每次进入页面时自动开启 30 秒的倒计时效果demo(整理)

<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();
}

猜你喜欢

转载自blog.csdn.net/qq_38881495/article/details/125785715