美文网首页1024
16、Vue3 declare it using the "e

16、Vue3 declare it using the "e

作者: 圆梦人生 | 来源:发表于2021-02-04 09:02 被阅读0次

Vue3中 子组件通过emit抛出事件 出现如下警告但不影响使用:
Extraneous non-emits event listeners (otherev) 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.

解决方法,需要在emits中定义抛出的事件名

案例

<template>
  <input type="text" :value="name" @input="$emit('update:name', $event.target.value)">
  <input type="text" :value="title" @input="$emit('update:title', $event.target.value)">
  <input type="text" @input="$emit('otherev', $event.target.value)">
</template>

<script>
export default {
    props: {
        name: String,
        title: String
    },
    // 定义抛出的事件名称
    emits: ["update:name", 'update:title', 'otherev']
}

</script>

相关文章

网友评论

    本文标题:16、Vue3 declare it using the "e

    本文链接:https://www.haomeiwen.com/subject/wazptltx.html