这篇文章主要介绍了微信小程序日历插件代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
1.wxml代码
<view class="timePick">
<picker mode="date" fields="month" value="{{timestamp}}" start="1999-01-01" end="2999-12-12" bindchange="datePickerBindchange">
{{dateValue}}
</picker>
</view>
2.js
data: {
searchDate:"",
timestamp:""
},
onLoad: function(options) {
//日历默认值设置
this.timestamp=new Date().getTime()
},
datePickerBindchange:function(e){
let date = e.detail.value+'-01 00:00:00.0';
date = date.substring(0,19);
// date = date.replace(/-/g,'/');
let timestamp = new Date(date).getTime(); //插件再次打开时日期
let picktime=e.detail.value
let timeString=picktime.replace(/-/g,'年')+'月';
// this.setData({
// dateValue:e.detail.value
// })
this.setData({
searchDate:date,
// searchDate:picktime,
dateValue:timeString, //1019年12月
timestamp:picktime,
})
}