问题
打开微信小程序,随便创建一个页面(不妨设置为test)。然后,在test.js文件中加入如下代码:
data: {
times: 0
},
/**
-
生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;var term = setInterval(function () {
console.log(‘times:‘,that.data.times);
if (that.data.times ===3) {
clearInterval(term);
console.log(‘END...‘);
}else{
that.setData({ times: ++that.data.times})
}
}, 1000);
},请问:控制台的输出结果如何?
如果把上述代码完全替换为如下:
data: {
times: 0
},
/**
-
生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;var term = setInterval(function () {
console.log(‘times:‘,that.data.times);
if (that.data.times ===3) {
clearInterval(term);
console.log(‘END...‘);
}else{
that.setData({ times: that.data.times++})
}
}, 1000);
},