element-ui el-datepicker动态获取disabledDate限制日期范围

代码

 <template>
     <el-date-picker
         type="daterange"
         value-format="yyyyMMdd"
         format="yyyy-MM-dd"            	  
         placeholder="选择日期"
         range-separator="至"
         v-model="form.date"
         :picker-options="pickerOptions"
         unlink-panels>
     </el-date-picker> 
 </template>
 <script>
	export default {
		data() {
			return {
				form: {
					timeUnit: 1
				},
  				pickerOptions: {
					disabledDate: this.disabledDate
				}
  			}	
		},
		methods: {
			disabledDate(time) {
	           if (this.form.timeUnit == '1') {
               	return time.getTime() > Date.now();
	           } else {
                  return time.getTime() > Date.now() - 8.64e7;
               }
          }
	   }
	}
 </script>

根据form.timeUnit来计算日历控件disabledDate范围。

你可能感兴趣的:(JavaScript,Vue.js)