<script>
export default {
name: 'App',
mounted() {
//开发环境不需要提示
if (process.env.NODE_ENV === 'development') return
this.$nextTick(() => {
window.addEventListener('beforeunload', this.beforeUnload)
})
},
beforeDestroy() {
if (process.env.NODE_ENV === 'development') return
window.removeEventListener('beforeunload', this.beforeUnload)
},
methods: {
beforeUnload(e) {
if (!this.$store.state.user.isLeaveToast) {
// 系统中调用location.reload()刷新,isLeaveToast设置false也不需要刷新
this.$store.commit('user/SET_TOAST', true)
return false
}
e = e || window.event
if (e || window.event) e.returnValue = 1;
return 1;
}
}
}
</script>
关闭浏览器窗口弹出提示框(vue项目)
于 2023-08-22 11:13:25 首次发布