鍍金池/ 問答/HTML/ vue頁面緩存之后,再回到之前頁面,時(shí)間組件報(bào)錯(cuò)

vue頁面緩存之后,再回到之前頁面,時(shí)間組件報(bào)錯(cuò)

設(shè)置緩存

handleShow (card) {
        if (!this.form.activityEndTime) {
          this.$message.error("請先選擇活動(dòng)結(jié)束時(shí)間");
          return ;
        } else if (this.selectTicket.length < 10){
          this.$refs.dialog.show(null, this.form.activityEndTime);
        } else {
          this.$message.error("最多只能添加10張優(yōu)惠券");
        }
        localStorage.setItem("activitySaved",JSON.stringify(this.form));
        let test = JSON.parse(localStorage.activitySaved);
        console.log(test);
      },

通過特定頁面進(jìn)入讀取緩存

 beforeRouteEnter (from, to, next) {
      next(vm => {
        if (to.path.includes('/MarketingManage/Coupon/AddCoupon')) {
          if (localStorage.getItem('activitySaved')){
            vm.form = JSON.parse(localStorage.activitySaved);
            console.log(2,vm.form.activityStartTime);
          }
        }
      });
    },

讀取之后

clipboard.png

return {
      startPickerOptions: {
        disabledDate (currentDate) {
          console.log(2,_this.form.activityStartTime);
          return _this.$moment().startOf('days').valueOf() > currentDate.getTime()
            || (_this.form.activityEndTime && currentDate.getTime() > _this.form.activityEndTime.getTime());
        }
      },
      endPickerOptions: {
        disabledDate (currentDate) {
          return (_this.$moment().startOf('days').valueOf() + 86400000) > currentDate.getTime()
            || currentDate.getTime() <= _this.form.activityStartTime.getTime() - 86400000;
        }
      },
      startTime: minutes >= 30 ? _this.$moment().add(1, 'hours').format('HH:00') : _this.$moment().format('HH:30'),
      endTime: '00:00',
      commitStatus: true
    };
  },
回答
編輯回答
尛憇藌

因?yàn)槟銖膌ocalstorage里取出來的activityStartTime只是個(gè)字符串,不是個(gè)Date對象了

2018年3月1日 08:59