vue获取前一天前两天


    // 前一天
    beforeDay() {
      //前一天
      let beforeDay = new Date(
        new Date(this.alarmformSearch.date).getTime() - 24 * 60 * 60 * 1000
      ); //计算当前日期 -1
      this.alarmformSearch.date = this.convertToDate(beforeDay); //格式化日期并赋值

      this.getWarnInfo();
    },

    // 前两天
    beforeTwoDay() {
      //前一天
      let beforeTwoDay = new Date(
        new Date(this.alarmformSearch.date).getTime() -
          24 * 60 * 60 * 1000 -
          24 * 60 * 60 * 1000
      ); //计算当前日期 -1
      this.alarmformSearch.date = this.convertToDate(beforeTwoDay); //格式化日期并赋值

      this.getWarnInfo();
    },

    convertToDate(date) {
      var date = new Date(date);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      var d = date.getDate();
      m = m < 10 ? "0" + m : m; //月小于10,加0
      d = d < 10 ? "0" + d : d; //day小于10,加0
      return y + "-" + m + "-" + d;
    },

你可能感兴趣的:(vue,vue)