Page({
data: {
hours :0,
minute :0,
second :0,
startTime : 1647233688,
timeDifference :''
},
onLoad: function (options) {
var that=this
setInterval(timeDifference,1000)
},
timeDifference: function(){
var endTime = Date.parse(new Date());
var usedTime = endTime - this.data.startTime
var firststep_hours = usedtime % (24*60*60*1000);
var hours = Math.floor(firststep_hours / (60*60*1000));
var firststep_minute = firststep_hours % (60*60*1000);
var minute = Math.floor(firststep_minute / (60*1000));
var firststep_second = firststep_minute % (60*1000);
var second = Math.floor(firststep_second / 1000);
that.setData({
hours: that.timeDifference.hours,
minute: that.timeDifference.minute,
second: that.timeDifference.second
});
return hours;
}
setInterval(this.timeDifference,1000) y以后报错信息原样拷贝出来,更便于确认问题 h还有that.setData,用this,你that在onload定义,却在别的方法里调用,无语哦