小程序时间选择器报错getFullYear is not a function 的解决方案
var date = new Date(time)
效果
点击 “展示弹出层”右侧箭头弹出
选择日期后
整体用法
.json
"usingComponents": {
"van-datetime-picker": "@vant/weapp/datetime-picker/index",
"van-cell": "@vant/weapp/cell/index",
"van-cell-group": "@vant/weapp/cell-group/index",
"van-popup": "@vant/weapp/popup/index"
}
.wxml
<van-cell title="展示弹出层" is-link bind:click="showPopup">{{ spdate }}</van-cell>
<van-popup show="{{ show }}" bind:close="onClose" position="bottom" custom-style="height: 50%">
<van-datetime-picker type="date" bind:confirm="confirmPicker" value="{{ currentDate }}" min-date="{{ minDate }}"/>
</van-popup>
.js
data: {
//时间选择
spdate: '',
show: false,
currentDate: new Date().getTime(),
minDate: new Date().getTime()
},
// 时间选择
showPopup() {
this.setData({ show: true });
},
onClose() {
this.setData({ show: false });
},
confirmPicker(val) {
// 时间转化
var time = val.detail
var date = new Date(time)
var date = (date.getFullYear()) + "-" + (date.getMonth() + 1 + "-" + date.getDate())
this.setData({
spdate: date,
show: false
})
},
困扰了我2天的时间选择 终于算是整出来了,currentDate和minDate可以根据需要修改
参考