019、子组件向父组件传递参数 this.$emit

文章目录

1、this.$emit

this.$emit 是 Vue.js 中一个非常重要的方法,它允许子组件向父组件发送自定义事件,并传递数据。

基本用法:

  • 子组件

    this.$emit('eventName', data);

  • 父组件
    注意 eventName 和 子组件声明的一致,父组件函数名的定义有一个入参,但是只需写一个函数名

    <TagsMenu @eventName="父组件函数名" />