收藏
回答

picker date模式不能选择今天以后的日期,出现1900 - 1 - 01

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug picker 微信安卓客户端 7.0.6 2.8.0

<view class='picker-container'>

  <picker mode='date' value='{{ picker.startDate }}' start='{{ startLimit }}' end='{{ picker.endDate }}' bindchange='getPickerValue' data-key='picker.startDate'>
    <view class='label fs-32 c-gray'><text>开始日期</text> {{ picker.startDate }}</view>
  </picker>
  <picker mode='date' value='{{ picker.endDate }}' start='{{ picker.startDate }}' bindchange='getPickerValue' data-key='picker.endDate'>
    <view class='label fs-32 c-gray'><text>结束日期</text> {{ picker.endDate }}</view>
  </picker>
</view>
const miment = require('miment')
 
Page({
    data: {
        picker: {
            startLimit: "",
            startDate: "",
            endDate: "",
            realEndDate: "",
        }
    },
 
    onload() {
        this.initPicker()
    },
 
    initPicker() {
        const FORMATER = 'YYYY-MM-DD'
        const today = new Date()
        const picker = {
            startLimit: miment(new Date(0)).format(FORMATER),
            startDate: miment(today.getFullYear(), today.getMonth() - 1, today.getDate()).format(FORMATER),
            endDate: miment(today.getFullYear(), today.getMonth(), today.getDate()).format(FORMATER),
        }
 
        if (new Date(picker.startLimit).getTime() > new Date(picker.startDate).getTime()) {
            picker.startDate = picker.startLimit
        }
        this.setData({
            picker
        })
    },
 
    getPickerValue(e) {
        const { key } = e.currentTarget.dataset
        this.setData({
            [key]: e.detail.value
        })
    },
}

渲染后的 wxml表现为



System: Android6.0.1

WeChat: 7.0.6 1460

WeChatLib: 2.8.0 (2019.8.8 20:04:12)


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签