用于子传父:$emit 触发父函数,可以向外传参。

子组件可以使用 $emit,让父组件监听到自定义事件 。

//父组件:
<child @childMsg="showChildMsg"></child>
//子组件
<button @click=" this.$emit("childMsg","hello world!"); ">向父组件传值</button>