代码片段
https://developers.weixin.qq.com/s/GSjXzCmI7BH5
index.js 定义倒计时秒数
data: {
list: [
{ time: 900 },
{ time: 600 },
{ time: 300 },
{ time: 800 },
]
},
index.wxml
倒计时自定义组件中接收数据
properties: {
title: {
type: String,
value: '倒计时',
observer(n, o, c) {}
},
time: {
type: Number,
value: 0,
observer(n, o, c) {}
}
},
倒计时自定义组件中的方法
countdowns(){
var timeNow = that.data.timeNow; //properties接收的time赋值给data中的timeNow
var minute=Math.floor(timeNow / 60 );
var second=timeNow % 60
second<10?second='0'+second:'';
that.setData({
countdown:minute+'分'+second+'秒',
timeNow: that.data.timeNow-1
})
setTimeout(that.countdowns, 1000);
},
其中取到的秒数也很奇怪,救一下
给你改了下:
https://developers.weixin.qq.com/s/qdmheCmK7wHf
然后你说的调用几次就会一下跳几秒,是因为你启了定时器,刷新的时候并没有被停掉。你没有调用cleartimeout