小程序 - 倒计时

let timerFn = null;
const wxTimer = require('../util/wxTimer.js');

Page({
	data: {
		date: '2019/03/14 18:00'
	},

	onLoad: function () {
		const td = this.data;

		timerFn = new wxTimer({
			endTime: new Date(td.date).getTime(),
			beginTime: Date.now()
		});

		timerFn.start(this);
	},

	onShow: function () {
		if (!this.data.canShow) return;

		if (timerFn) {
			timerFn.calibration();
			timerFn.start(this);
		}
	},

	onHide: function () {
		timerFn && timerFn.stop();
	},

	changeTime: function (e) {
		this.data.time = e.detail.value;
		this.onHide();
		this.onLoad();
	},
});
<view wx:if="{{timer.time}}" class="time flex ac jc">
	<text>{{timer.date}}</text>天
	<text>{{timer.hours}}</text>时
	<text>{{timer.minutes}}</text>分
	<text>{{timer.seconds}}</text>秒
</view>

<picker class="flex ac jc" mode="time" bindchange="changeTime" value="{{time}}">
	<text>{{date}}</text>
</picker>

猜你喜欢

转载自blog.csdn.net/NaShiShiWo/article/details/88554010