element-ui设置日期选择,并给日期范围赋默认值


        
        
      
created() {
    this.getProjects();
    // 设置开始日期为前30天,结束日期是当前日期,注意使用$set来设置!
    let startDate = this.getThreeDaysAgo();
    let endDate = this.getToday();
    this.$set(this.queryParams, "dateRange", [startDate, endDate]);
  },
 // 获取当前日期
    getToday() {
      //获取当前日期
      let myDate = new Date();
      let nowY = myDate.getFullYear();
      let nowM = myDate.getMonth() + 1;
      let nowD = myDate.getDate();
      let endDate =
        nowY +
        "-" +
        (nowM < 10 ? "0" + nowM : nowM) +
        "-" +
        (nowD < 10 ? "0" + nowD : nowD); //当前日期
      return endDate;
    },
// 获取三十天之前的日期
    getThreeDaysAgo() {
      let myDate = new Date();
      let lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30); //最后一个数字30可改,30天的意思
      let lastY = lw.getFullYear();
      let lastM = lw.getMonth() + 1;
      let lastD = lw.getDate();
      let startData =
        lastY +
        "-" +
        (lastM < 10 ? "0" + lastM : lastM) +
        "-" +
        (lastD < 10 ? "0" + lastD : lastD); //三十天之前日期
      return startData;
    },

你可能感兴趣的:(vue.js,前端,js,elementui)