美文网首页
vue 父组件调用子组件方法,子组件触发父组件方法

vue 父组件调用子组件方法,子组件触发父组件方法

作者: hsqin | 来源:发表于2019-12-11 14:26 被阅读0次

parent.vue -- 父组件
childItem.vue -- 子组件

  • 父组件页面内容
<child-item ref="childPart" @someChange="childChange"></child-item>

childChange(val){
  console.log(' 这是父组件中的方法 ')
}
  • 子组件页面内容
parentHandlerClick(param){
 console.log('这是子组件的方法,父组件调用  ',param)
}
1,子组件调用父组件方法
//子组件页面
this.$emit("someChange",val);
2,父组件调用子组件方法
// 父组件页面
this.$refs.childPart.parentHandlerClick(param)

相关文章

网友评论

      本文标题:vue 父组件调用子组件方法,子组件触发父组件方法

      本文链接:https://www.haomeiwen.com/subject/xtbogctx.html