vue+element设置仅近一年时间可选

 

<el-date-picker
              format="yyyy-MM-dd"
              v-model="form.dataRange"
              :picker-options="pickerOptions"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>

 

pickerOption对象设置在data里边:

pickerOptions: { // 限制查询时间为近一年内
        disabledDate(time) {
            let t = new Date();
            let Y = t.getFullYear();
            let M = t.getMonth()+1;
            let D = t.getDate();
         return (time.getTime() < new Date(Y-1,M,D).getTime()||time.getTime() > new Date(Y,M,D).getTime())
        }
        }

 

posted @ 2021-09-01 18:17  砌墙的砖  阅读(705)  评论(0编辑  收藏  举报