<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>