Vue 中父组件和子组件之间获取对方数据和方法

版权声明:本文为博主原创文章,转载请注明作者和出处,如有错误,望不吝赐教。 https://blog.csdn.net/weixin_41888813/article/details/84647013

父组件获取子组件的数据和方法

one

在父组件中调用子组件时,定义一个ref(其实和选择器类似):

<Common  ref="commonChild" :pathologyId="form.pathologyId" />

在父组件中获取子组件属性和方法写法:

this.$refs.commonChild.属性

this.$refs.commonChild.方法


two

Vue官网上有这个实例属性,但使用需要自定义组件顺序

 


 子组件获取父组件的数据和方法

在子组件中获取父组件属性和方法写法:

this.$parent.属性

this.$parent.方法


参考来源于:

https://cn.vuejs.org/v2/api/#vm-children

https://blog.csdn.net/zhongshijun521/article/details/80610971 

猜你喜欢

转载自blog.csdn.net/weixin_41888813/article/details/84647013