1、父组件调用子组件的方法
父组件中:(关键字$refs、ref)
<component ref="childFunc"></component>
this.$refs.childFunc.childAlert();
子组件中:
childAlert () {
alert('被父组件调用到了!')
}
2、子组件调用父组件的方法
父组件中:
<component @fatherfunction="fatherfunction"></component>
fatherfunction(val) {
alert(val)
}
子组件中:(关键字$emit)
this.$emit('fatherfunction', '父组件被调用');
本文介绍Vue.js中父组件与子组件互相调用方法的技术细节,包括如何使用$refs及$emit实现跨组件通信。


被折叠的 条评论
为什么被折叠?



