子组件写法:
<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')"