日期选择器禁止选择当前日期之前和两年之后的日期

      
          
            
              
                {{
                  dateState == true ? date : "请选择"
                }}
              
            
          
        
  bindDateChange: function(e) {
      this.dateState = true;
      this.date = e.target.value;
      console.log(this.date, "daa");
      this.form.accessTime = e.target.value;
    },
  getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === "start") {
        year = year - 60;
      } else if (type === "end") {
        year = year + 2;
      } else if (type === "iiiup") {
        year = year;
      }
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;
      return `${year}-${month}-${day}`;
    },
export default {
  data() {
    const currentDate = this.getDate({
      format: true,
    });
    return {}
 }
}

  computed: {
    endDate() {
      return this.getDate("end");
    },
  
    iiiupDate() {
      return this.getDate("iiiup");
    },
  },

==========
这个是获取当前日期前一天=》
date 代表指定的日期,
day 传-1表始前一天,传1表始后一天

    getYes(date, day) {
      var dd = new Date(date);
      dd.setDate(dd.getDate() + day);
      var y = dd.getFullYear();
      var m =
        dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
      var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      console.log(dd, "dd", y, "y", m, "m", d, "d");
      return y + "-" + m + "-" + d;
    },
  computed: {
      upDate() {
          return this.getYes(new Date(), -1);
        },
}

你可能感兴趣的:(日期选择器禁止选择当前日期之前和两年之后的日期)