el-date-picker 限制只能選擇當年的日期


<template>
  <div>
    <el-date-picker v-model="dataForm.jjDate" placeholder="獎懲時間" style="width: 240px;" type="datetime"
      @change="cDatePicker" :picker-options="expireTimeOption" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataValidate:'',
      dataForm:{
        jjDate:''
      },
      expireTimeOption: {
        disabledDate(date) {
          //disabledDate 文檔上:設置禁用狀態,參數為當前日期,要求返回 Boolean
          return (
            date.getTime() < new Date(new Date().getFullYear(),0,1).getTime() ||
            date.getTime() > new Date(new Date().getFullYear(),11,31).getTime()
          );
        }
      }

    };
  },
  methods: {
    cDatePicker(vm){
      const year= vm.split('-')[0]
      const conYear = new Date().getFullYear();
      this.dataValidate = "";
      if(year !== conYear){
        this.dataValidate = "";
      }
    }
  }
}
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM