其他分享
首页 > 其他分享> > vue后退

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()
      }
    }

 

标签:stringify,vue,subtitle,title,后退,flag,next,JSON
来源: https://www.cnblogs.com/ronle/p/10833356.html