子组件写法:

 

<div @click="childClick">子组件</div>

childClick(){
  this.$emit("emitClick","from child")
}

 

父组件写法:

 

<div @emitClick="parentClick($event,'from parent')">父组件</div>

parentClick(child,parent){
  console.log(child,parent)//from child from parent
}

 

解析:父组件 parentClick 函数的参数中, $event 就代表从子组件传递过来的参数(即:"from child"),后面可以跟任意的额外参数,上面的示例中传入的额外参数为 "from parent",如果有需要,可以传入更多的额外参数,如 @emitClick="parentClick($event,'from parent','param1','param2')"

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-02-05
  • 2021-06-14
猜你喜欢
  • 2021-11-10
  • 2021-09-22
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案