Look at the effect
Because of the weak web experience--at first my idea was to look for events, but for half a day the API was basically click Touch, triggered by physical
I actually ignore the life cycle, life cycle + thread is not completely OK ~
It turns out that thread is the kingly way.
Degree Niang above also looked a lot of is to use JS to write, but, probably just did not have a few days, I to JS and micro-Letter Small program Master is not skilled
Ideas:
- Onload:function (Options) Call Countdown method function
- Defining threads for data dynamic reality
1. Date converted into milliseconds
2. Define the thread dynamic display
3. Render Countdown
1. Milliseconds to convert to fixed format
2. To deal with the short and minute digits of the supplement 0
Look at the code.
Wxml:
<viewclass= "Pay_time" >
<image src= ' {imgurls_pay_time}} ' ></image>
<text> Payment remaining time:</text>
<text>{{clock}} </text>
</view>
|
WXJS:
Pages/order/take_order/pay/pay.js
Imgurls_pay_time: '/image/icon_orderstatus_countdown.png ',
Onload:function (options) {
Page initialization options The parameters that are brought by the page jump
* * Millisecond Countdown *
2016-12-27 12:47:08 Convert date format
var a = That.data.expireTime.split (/[^0-9]/);
Due Date: date to milliseconds
var expirems = new Date (a[0], a[1]-1, a[2], a[3], a[4], a[5]);
var duringms = Expirems.gettime ()-(New Date ()). GetTime ();
Clock:that.date_format (DURINGMS)
Clock: "Payment has been closed, please order again"
Timeout is jumping out of recursion.
settimeout (function () {
Date_format:function (Micro_second) {
var second = Math.floor (micro_second/1000);
var hr = Math.floor (second/3600);
var min = That.fill_zero_prefix (Math.floor (SECOND-HR * 3600)/60));
var sec = Fill_zero_prefix (second%);//equal to => var sec = second% 60;
return hr + ":" + min + ":" + sec + "";
* * The number of seconds to fill 0 * *
Fill_zero_prefix:function (num) {
Returnnum <10? " 0 "+ num:num
|
Tip
If you do not make a bit of 0
will display the following