mounted () {
// 註冊監聽
window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
},
destroyed () {
// 非窗口關閉的跳轉直接卸掉監聽
window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
},
methods: {
// 父窗口關閉方法
beforeunloadHandler (e) {
// 關閉父窗口
window.opener && this.flushArr.includes(window.opener.location.pathname) && window.opener.location.reload()
// 也可以只調用父窗口方法刷新數據(需要在父窗口中手動爲window創建一個調用方法的方法)
// window.opener && this.flushArr.includes(window.opener.location.pathname) && window.opener.backToday()
}
}
mounted() {
// 將backToday方法綁定到window下面,提供給外部調用
window['backToday'] = () => {
this.goToday()
}
},