Vue中父窗口新开的子窗口关闭的时候刷新父窗口
mounted () {// 注册监听window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))},destroyed () {// 非窗口关闭的跳转直接卸掉监听window.removeEventListener('beforeunload', e => this.b...
·
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()
}
},
更多推荐
已为社区贡献4条内容
所有评论(0)