费不多说,直接代码:
`// pages/test1/test1.js var num = 10, interval = null, min = 0; Page({ /** * 页面的初始数据 */ data: { time:10 }, onClickTimeStart(){ startTime(); } , startTime: function(){ console.log("开始点击"); var that = this; interval = setInterval(function(){ console.log(num + "-- 循环次数"); num--; if(num <= min){ clearInterval(interval); wx.showToast({ title: '结束了', icon: '', image: '', duration: 1, mask: true, success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) } that.setData({time:num}) },1000); } })`