RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
小程序最最最基础编程之计时器使用

对于JS编程高手可略过此文,仅供新手学习参考。

创新互联主营政和网站建设的网络公司,主营网站建设方案,手机APP定制开发,政和h5小程序开发搭建,政和网站营销推广欢迎政和等地区企业咨询

问题

打开微信小程序,随便创建一个页面(不妨设置为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);
    },

请问:控制台的输出结果又将如何?

[参考答案]自己试去......


分享名称:小程序最最最基础编程之计时器使用
链接地址:http://sczitong.cn/article/gggcoc.html