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()
    }
},

 

Logo

前往低代码交流专区

更多推荐