element-ui时间日期选择器限制时间到分

775 阅读1分钟

今日做了个需求记录一下:

要求只能选择当前时间以及未来三个月限制到分钟

//组件写法
<el-date-picker v-model="mappingTime" type="datetime" placeholder="选择日期时间"  
:picker-options="pickerOptions"> </el-date-picker>

//组件的传入配置,直接写在Vue2版本的data里
     pickerOptions: {
        disabledDate(time) {
          let curDate = (new Date()).getTime();
          let three = 90 * 24 * 3600 * 1000;
          let threeMonths = curDate + three;
          return time.getTime() < Date.now() || time.getTime() > threeMonths;//选择当前时间之后和三个月内的
          // return time.getTime() > Date.now(); //选择当前时间之前的也写一下

        },
        //这个是限制分钟的
        selectableRange: `${moment().locale('zh-cn').format('HH:mm:ss')} - 23:59:59`
      },