微信小程序 定时更新

微信小程序

18-8-23 15:36:40


const app = getApp()
var timer
Page({
data:{
str:'',
i:0
},
onLoad: function () {
},
// 自定义的开始按钮
startBtn: function () {
console.log("开始按钮");
this.Countdown();
},

  // 自定义的暂停按钮
pauseBtn: function () {
console.log("暂停按钮");
clearTimeout(timer);
},
Countdown: function () {
var that=this;
timer = setTimeout(function () {
console.log("----Countdown----");
that.setData({
str: "asdsadsadasd" + that.data.i,
i: that.data.i+1
});
that.Countdown();
}, 1000);
}
})

----------------------------------------------------------------------------------------------------

<!--index.wxml-->
<view class="container">
<text bindtap="startBtn" >开始</text>
<text bindtap="pauseBtn" >停止</text>
<text >{{str}}</text>
</view>