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', '父组件被调用');