-
问题:
用户需求是当用户在创建商品时,点击了左侧菜单,做一个离开提醒‘是否确定离开?’。
如下实现:
但是,出现一个问题:用户点击左上角浏览器回退按钮时,这个弹出提醒就会闪现,立马消失。请教大神们~~beforeRouteLeave(to, from, next) { console.log(' beforeRouteLeave !', this) if (this.isSubmit=='1' || this.saveLoading == true || this.cancleFlag ==true || this.previewFlag == true) { //去除这三种情况 不用离开提醒 next() } else { this.$confirm('确定离开?请保存数据!', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { next() }).catch(() => { next(false) }); } },
解决方案