Use a simple countdown function to test the direct relationship between the page and js code in the mini program development platform.
The functions to be implemented are as follows
1, the countdown effect from 60 to 0
2, there will be a prompt after the countdown is completed
The effect is as follows:
In fact, the implementation code is very simple
<!--index.wxml--> <view class="container"> <text>倒计时: {{second}} </text> </view>
The following is the corresponding js processing
//index.js // 从从60到到0倒计时 function countdown(that) { var second = that.data.second if (second == 0) { that.setData({ second: "60秒倒计时结束" }); return ; } var time = setTimeout(function(){ that.setData({ second: second - 1 }); countdown(that); } ,1000) } Page({ data: { second: 60 }, onLoad: function() { countdown(this); }
The above is the detailed content of Sample code to implement countdown effect in mini program. For more information, please follow other related articles on the PHP Chinese website!