uniapp选择日期

<picker mode="date" :value="getDate" :start="getDate('start')" :end="getDate('end')" @change="selectDate">
    <view class="date-screen">日期筛选</view>
</picker>



//处理日期选择组件的日期数据
getDate(type) {
    const date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
			
    if (type == 'start') {
        year = year - 5;  //设置年份区间
    } else if (type == 'end') {
        year = year + 5;
    }
    month = month > 9 ? month : '0' + month;;
    day = day > 9 ? day : '0' + day;
    return `${year}-${month}-${day}`;
},
//选择日期,获取选择结果
selectDate(e){
    let dateValue=e.target.value
    console.log(dateValue)
},

posted @ 2021-05-19 15:57  huihuihero  阅读(1557)  评论(0编辑  收藏  举报