VUE 子窗口如何调用父窗口的方法-- PC端项目

父窗口页面:parent.vue

 1 <script>
 2 export default {
 3   data() {
 4     return {
 5     };
 6   },
 7   mounted() {
 8   },
 9   created() {
10     let _this = this
11     window.handleList=function(obj){
12       //obj为子窗口传递的参数
13       _this.handleGetList();
14     }
15   },
16   methods: {
17     // 获取列表数据
18     handleGetList(){
19       //获取列表的代码
20     },
21     //打开子窗口
22     handleOpen(){
23       window.open('#/child')
24     }
25   }
26 };
27 </script>

子窗口页面:child.vue

<script>
export default {
  methods: {
    // 操作父窗口代码
    handleOperationParent(){
      //window.opener && !window.opener.close判断父组件是否存在
      if(window.opener && !window.opener.close) {
        //handleList为父窗口的window.handleList方法名 obj为参数 可以不传递
        window.opener.handleList(obj);
        // window.close() 关闭当前页面
      }
    }
  }
};
</script>
原文地址:https://www.cnblogs.com/ruishuiweixiang/p/14578152.html