1、直接在子组件中使用
this.$parent.fatherMethod();
其中fatherMethod是方法名
2、$emit
在父组件中需要对子组件进行方法注册(好比prop传参,如下写)
@fatherMethod="fatherMethod"
(其中前者是注册的名字,在子组件中使用,后者是在父组件中的方法名)
在子组件中直接使用(子组件中使用的名字要与注册时前者的名字相同)
this.$emit('fatherMethod');
3、使用prop传参,将方法直接传入
父组件中
:fatherMethod="fatherMethod"
子组件中先接收,后使用
props: {
fatherMethod: {
type: Function,
default: null
}
},
this.fatherMethod();
网友评论