Vue 3:即使存在发出警告也会发出警告

mig*_*iga 4 javascript vue.js

我收到以下警告:

[Vue warn]: Extraneous non-emits event listeners (addData) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the "emits" option. 
  at <UserData onAddData=fn<bound dataSubmit> > 
  at <App>
Run Code Online (Sandbox Code Playgroud)

在我的 Vue3 应用程序中。我emits:["add-data"]在 UserData.vue 中使用,但仍然出现警告。下面是vue项目的相关部分:

应用程序

[Vue warn]: Extraneous non-emits event listeners (addData) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the "emits" option. 
  at <UserData onAddData=fn<bound dataSubmit> > 
  at <App>
Run Code Online (Sandbox Code Playgroud)

用户数据.vue

<template>
<div class="columns">
    <div class="column">
        <user-data @add-data="dataSubmit" />
    </div>
    <div class="column">
        <active-user @delete-user="deleteUser" v-for="user in users" :key="user.id" :name="user.name" :age="user.age" :id="user.id" />
    </div>
</div>
</template>

<script>
export default {
    data() {
        return {
            users: []
        }
    },
    methods: {
        dataSubmit(name, age) {},
        deleteUser(id) {}
    }
}
</script>
Run Code Online (Sandbox Code Playgroud)

主文件

<template>
<h2>Add new user:</h2>
<form @submit.prevent="submitData">
    <label>Name*</label>
    <input type="text" v-model="name" placeholder="Name" />

    <label>Age*</label>
    <input type="text" v-model="age" placeholder="Age" />

    <button>add</button>
</form>
</template>

<script>
export default {
    emits: ["add-data"],
    data() {
        return {
            name: "",
            age: ""
        }
    },
    methods: {
        submitData() {
            this.$emit("add-data", this.name, this.age)
        }
    }
}
</script>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但它只显示警告。

如果我将emits零件更改emits: ["add-data", "addData"]为警告消失。

ski*_*tle 5

有一个开放的错误:

https://github.com/vuejs/vue-next/issues/2540

现在你需要使用emits: ['addData']来避免警告。