vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Home Page:https://vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple Dom nodes in template use emits will warn Extraneous non-emits event listeners (eventName) were passed to component but could not be automatically inherited

PolanZ opened this issue · comments

Vue version

latest

Link to minimal reproduction

https://play.vuejs.org/#eNp9UsGO0zAQ/ZWpL+1Km0bLclrSClhVAg6AAMHFlyiZtt51bMt22qIo/86MQ9oglb155j3PvJl5nXjn3PLQongQRai8chECxtatpVGNsz5CBx630MPW2wbmRJ2/OWOPtnE/W/yLLXOOuRpTpKmsCRGasIMV11jMP6DWFn5Zr+vZ/OZC2Zem1viobUCiLm5gtYaupxpFPmgiNRREbJwuI1IEUOzv1l2Xqvd9kVOUssq4NsIha2yNeiUF4VJAPoCj3LcVtyJ00lgKJhX5pIm4FTGQwq3aLZ+CNbSjjutIUVEhpdF/cVHRBFI8QEIYK2nG46eUi77F2zFf7bF6vpJ/CifOSfHVY0B/ICVnLJZ+h3GAN98/44neZ5BGbDWxXwC/YbC6ZY0D7X3L8/oJL6n9mK6pzO5H2JwimjAOxUKZ2Se+FHRa3uH/Rr/IvV++Tv+k6WmLoy2umGwwADYq0uVr3CqDGwrCghY2nOWKT1T1fPEJ9+H/kx/kHOr8knlqdUgPgLtX98OjCNrG0Sn5SChmWQZNaX5DTRb3lihHpTUcS2/AWJNx6wBZdq7L7iKBE3dRJMU6ZaHB2Vj8X6/1fwDAgyyT

Steps to reproduce

simple demo

Only the component use multipart dom nodes and use emiti, will warning non-emits. the code you can get.

App.vue

<script setup>
import { ref } from 'vue';
import CompVue from './Comp.vue';

const msg = ref('Hello World!')

const handleClose = () => {};
</script>

<template>
  <h1>{{ msg }}</h1>
  <CompVue @close="handleClose"/>
</template>

Comp.vue

<script setup>
// if dynamic component how to add the defined ?
const emit = defineEmits(["close"])

const handleClick = () => {
  emit("close");
}
</script>

<template>
  <div>
    123
    <slot />
  </div>
  <!-- many dom root will warn non-emits -->
  <div @click="handleClick">click me!</div>
</template>

the console will warning tips:

[Vue warn]: Extraneous non-emits event listeners (close) 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. 

What is expected?

not warning

What is actually happening?

warn

[Vue warn]: Extraneous non-emits event listeners (close) 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 <Comp onClose=fn<handleClose> > 
  at <Repl>

System Info

No response

Any additional comments?

No response

// if dynamic component how to add the defined emits ?