vue对象比较,阻止后退
变量
data() { return { flag: false, form: { title: '', subtitle: "", }, } }
方法
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。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() } }

更多精彩