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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM