相关推荐recommended
【前端】在Vue页面中引入其它vue页面 数据传输 相互调用方法等
作者:mmseoamin日期:2023-11-30

1.this.$emit ,子传父

2.this.$children属性

this.$children返回的是数组

例子:

//获取子组件数据
       console.log(this.$children[0].cdata);
 //调用子组件方法
    this.$children[0].cmethod()

3.通过this.$refs获取组件

 //获取子组件数据
       console.log(this.$refs.test.cdata);
//调用子组件方法
    this.$refs.test.cmethod()

4.this.$parent获取父组件数据

this.$parent返回的是对象,this.$children返回的数组

例子:

 console.log(this.$parent.pdata);

主页面  home

从页面 headView

需求

        在 home.vue 中引用 headView.Vue

方案:

home.vue 代码:

只需要在home.vue 想要的地方添加