使用setInterval,报出了非函数而是对象的异常,如何解决?
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,改如何解决呢?