vue监听页面离开事件
var app = new Vue({ el: '#app', data() { }, mounted() { document.addEventListener('visibilitychange', this.handleVisiable) }, destroyed() { document.removeEventListener('visibilitychange', this.handleVisiable) }, methods: { handleVisiable(e) { // 监听页面离开事件 if (e.target.visibilityState === 'visible') { //返回页面 window.location.href = 'http://www.baidu.com' } } } })