vue后退

变量

data() {
      return {
        flag: false,
        form: {
          title: '',
          subtitle: "",
        },
    }
}

方法

beforeRouteLeave(to, from, next) {
      //let one= JSON.parse(JSON.stringify(this.form));
      let one = JSON.stringify({title: "1", subtitle: "2"});
      let two = JSON.stringify({title: "1", subtitle: "3"});

      if (one !== two && !this.flag) {
        next(false);
        setTimeout(() => {
          this.Confirm("数据没有保存,确定要退出吗?", () => {
            this.flag = true;
            this.$router.push({path: to.path})
          }, () => {
          });
        }, 500)
      } else {
        next()
      }
    }

 

上一篇:JS根据日期获取判断星期几


下一篇:愿一切安好!