data: function data() {
return {
"nowTime": ""
};
},
methods: {
timeFormate: function timeFormate() {
var year = new Date().getFullYear();
var month = new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
var date = new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate();
var hh = new Date().getHours() < 10 ? "0" + new Date().getHours() : new Date().getHours();
var mm = new Date().getMinutes() < 10 ? "0" + new Date().getMinutes() : new Date().getMinutes();
var ss = new Date().getSeconds() < 10 ? "0" + new Date().getSeconds() : new Date().getSeconds();
this.nowTime = year + "年" + month + "月" + date + "日" + " " + hh + ":" + mm + ':' + ss;
},
nowTimes: function nowTimes() {
this.timeFormate();
setInterval(this.nowTimes, 1000);
this.clear();
},
mounted: function mounted() {
this.nowTimes();
},
这么一段代码,可以正常运行,但是每一次循环都报setInterval expects a function as first argument but got object.;at setInterval callback function的异常,但是我打印this.nowTimes 的类型是function,改如何解决呢?
后面跟()啊!!!
看你timeFormate里的代码
怎么现在是setInterval(this.timeFormate, 1000);
setInterval(()=>{this.nowTimes}, 100)
请学会如何「提问」(👈戳我)
https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
请学会如何「提问」(👈戳我)