0
点赞
收藏
分享

微信扫一扫

父子组件如何互相调用接收值?

父组件调用子组件



子组件调用父组件

<child :fatherFun="handleFatherFun"><child>

子组件调用父组件的方法

$emit()

<div @click="childClick">点击调用父组件函数</div>

childClick() {//子组件点击
	this.$emit('fatherFun');//父组件的函数名
}

<child :father-fun="handleFatherFun"></child>

props 父元素使用props传值,父元素引用变量用命名-连接,不用驼峰 可以自定义type

<div @click="childCheck">点击调用父组件函数</div>
props: {
	fatherFun: {type: Function}
},
methods: {
	childClick() {
  	this.fatherFun();//父组件传过来的函数
  }
}

$parent

this.$prent.fatherFun();

举报

相关推荐

0 条评论