vue获取子组件数据的三个方法

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);
原文地址:https://www.cnblogs.com/luguankun/p/11700132.html