wxml文件
<picker mode="date" value="{
{currentDate}}" start="2021-01-01" end="2021-12-31" bindchange="bindDateChange"><view class="picker">日期选择: {
{
currentDate}}</view>
</picker>
js文件
const util = require('../../utils/util');
Page({
/*** 页面的初始数据*/data: {
// 日期筛选currentDate: util.getNowDate(new Date()),},// 日期筛选bindDateChange: function(e) {
this.setData({
currentDate: e.detail.value})},
})
util.js
const getNowDate = date => {
const year = date.getFullYear()const month = date.getMonth() + 1const day = date.getDate()return [year, month,day].map(formatNumber).join('-')
}
const formatNumber = n => {
n = n.toString()return n[1] ? n : `0${
n}`
}
module.exports = {
getNowDate:getNowDate
}