Warning "Extraneous non-emits event listeners" shows up even when emits is set
See original GitHub issueVersion
3.0.2
Reproduction link
https://codesandbox.io/s/vue-event-warning-bug-dqokg
Steps to reproduce
Create a fragment component with setup as render function. Then define a custom event. Listen to the custom event -> Warning should pop up in the console when loading the fragment component.
e.g. an input component as child component.
import { defineComponent, h } from "vue";
export default defineComponent({
props: {
msg: String
},
emits: ["test-change"],
setup(props, { emit }) {
return () => {
return [
h("h1", props.msg),
h("input", {
onChange: (evt) => emit("test-change", evt)
})
];
};
}
});
parent component:
<template>
<InputComponent
msg="string input"
@testChange="(evt) => console.log(evt.target.value)"
/>
</template>
<script>
import InputComponent from "./components/input";
export default {
name: "App",
components: {
InputComponent,
},
setup() {
console.log(InputComponent);
return {
console,
};
},
};
</script>
What is expected?
The warning should not appear.
What is actually happening?
A warning appears.
Extraneous non-emits event listeners (testChange) 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.
Events work fine.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (12 by maintainers)
Top Results From Across the Web
vue 3 emit warning " Extraneous non-emits event listeners"
I get the following warning. [Vue warn]: Extraneous non-emits event listeners (updatedcount) were passed to component but could not be ...
Read more >[Vue warn]: Extraneous non-emits event listeners - Get Help
I'm using Vue 3 with Vite. [Vue warn]: Extraneous non-emits event listeners (input) were passed to component but could not be automatically ...
Read more >vue 3 emit warning " Extraneous non-emits event listeners"
I think you need to define the emits in your component: https://v3.vuejs.org/guide/component-custom-events.html#defining-custom-events
Read more >Events | Node.js v19.3.0 Documentation
All objects that emit events are instances of the EventEmitter class. ... The following example shows a simple EventEmitter instance with a single...
Read more >A Guide to Vue Event Handling - with Vue 3 Updates - LearnVue
Emitting custom events. A common use case in any web framework is wanting a child component to be able to emit an event...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks ! That’s the solution ! 😃
@shadowings-zy In DOM, attribute names are always interpreted as lowercase by the browser. So in DOM hyphenized event names have to be used. This has always been a caveat in Vue and there’s no good way to “fix” without making event names too imprecise, so you can leave that be.