element-ui 日期组件选择只能在三个月内

element-ui 日期组件选择只能在三个月内

step1
参考element ui提供的一些方法
在这里插入图片描述
在这里插入图片描述
step2

data >> return写入 duration,定义为数组
注意:这里的this指向已改变,需在return 上方 let _this = this;

  pickerOptions:{
    
    
      disabledDate(time){
    
    
       let currentTime=_this.duration[0]
       let threeMonths=60*60*1000*24*90
       if(currentTime){
    
    
        return time.getTime() >currentTime.getTime() + threeMonths || time.getTime() < currentTime.getTime() - threeMonths
      	}
      },
      onPick({
    
    minDate,maxDate}){
    
    
        // 当第一时间选中才设置禁用
        if(minDate && !maxDate){
    
    
          _this.duration[0]=minDate
        }
        if(maxDate){
    
    
          _this.duration[1]=maxDate
        }
      }
    },

复制粘贴直接用就完事了,白给!

猜你喜欢

转载自blog.csdn.net/weixin_52400118/article/details/112762377