<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();
}
uniapp小程序,实现每次进入页面时自动开启 30 秒的倒计时。
最新推荐文章于 2022-08-09 10:19:28 发布