1、在应用类进行路由跳转、在需要提示的页面添加如下钩子函数
beforeRouteLeave (to, from, next) {
this.$confirm('当前页面数据还未保存,是否离开?', {
type: 'warning'
}).then(res => {
next()
}).catch(reason => {
next(false)
})
},
2、关闭网址或者浏览器时,提示用户
在需要提示的页面加入钩子函数
destroyed() {
window.onbeforeunload = null
},
mounted() {
window.onbeforeunload = function (e) {
e = e || window.event;
// 兼容IE8和Firefox 4之前的版本
if (e) {
e.returnValue = '关闭提示';
}
// Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
return '关闭提示';
}
},