vue 中 window.open打开的子路由如何调用上一个页面的方法

当遇到这个问题的时候第一次被这个问题难倒了。因为我这个还不是父子级别的页面。后来想了一下写个windows监听就可以解决问题。

1.A页面跳转到B页面

let resultScore = this.$router.resolve({
    
    
path: "/startPaper",
  query: {
    
    
    id: self.rowData.id
  }
});
window.open(resultScore.href, '_blank');

2. B页面发消息给A页面

window.opener.postMessage('getBatchRefresh', window.location)

3. A页面监听到消息调用方法

 mounted() {
    
    
      window.addEventListener('message', this.getBatchRefresh, false)
  },
 methods: {
    
    
 // 父页面的方法
  getBatchRefresh() {
    
    
     this.$refs.examBatchTable.$emit('vuetable:refresh')
   },
 }

以上就是问题的解决方案,如有抄袭请联系本人删除。

猜你喜欢

转载自blog.csdn.net/li22356/article/details/126955012