使用vue如何判断页面是否编辑及编辑页面未保存离开时,给出弹窗提示 [我也要出题](http://web.haizlin.cn/interview/)
Activity
liuyingbin19222 commentedon Apr 9, 2020
daiyoucheng commentedon Aug 18, 2020
在组件路由beforeRouterLeave中进行判断
lt846786463 commentedon Oct 27, 2020
watch() 监听数据变动
ferrinweb commentedon Nov 16, 2020
创建可编辑数据副本,如果有保存操作则更新副本。
在路由守卫钩子进行数据对比,如副本与原始数据不同,则给出 comfirm。
crush2020 commentedon Jan 20, 2021
使用watch监听数据的改变
newvalue:改变后的数据,oldvalue:改变前的数据
watch: {
name(newvalue, oldvalue) {
console.log(newvalue, oldvalue)
}
}
dengBox commentedon Jun 1, 2021
update钩子函数中设置flag,在beforeDestory根据flag进行弹框提示
sc950828 commentedon Sep 24, 2022
watch监听或者update监听都不严谨,有可能它改了又还原了。所以最好得把初始值保存起来,最后在beforeDestory中遍历比较。