-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning "Extraneous non-emits event listeners" shows up even when emits is set #2540
Comments
Seems to be related to defining it in camelCase works: emits: ['testChange'] ...but both should work ideally. |
this function doesn't take into account events defined in kebap-case: |
|
Hello, : ) |
your PR not fix this. |
Are you sure? I test the PR and warning not appear. And the unit test I add was passed |
here is my code, is there something wrong ?😭 <script src="../../dist/vue.global.js"></script>
<div id="app">
<Comp msg="string input" @testChange="(evt) => console.log(evt.target.value)"></Comp>
</div>
<script>
const { createApp, defineComponent,h } = Vue
const Comp = defineComponent({
props: {
msg: String
},
emits: ["test-change"],
setup(props, { emit }) {
return () => {
return [
h("h1", props.msg),
h("input", {
onChange: (evt) => emit("test-change", evt)
})
];
};
}
})
createApp({
components: {
Comp,
},
setup() {
console.log(Comp);
return {
console,
};
},
}).mount('#app')
</script> |
I think I find the reason. In in-DOM template, the |
I found this reason and I don't know how to fix this.😆 |
I have two ideas. The first is to show an additional warning for in-DOM component. As you see, the event you emit in in-DOM template works not fine. That is because in-DOM template is case sensitive. The second is fix the
Though the warning will disapper, the event is not worked..... So I prefer the first one. |
@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. |
When I use "@test-change" it does not log the evt. Example
I use the default eslint preset and this tells me, that custom event names should be kebab-case When I inspected my error messages all error messages contain the event name in camelcase, even when the event in the code is defined in kebabcase. Maybe the compiler changes the names. @ll-change="(evt) => handleStringInput(field)(evt)" Extraneous non-emits event listeners (llChange) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. |
Yes, in Vue3, we will convert the event name in camelcase, see issue #2249 |
As I am making the UI library with my team, we received multiple bug reports from our users because of the changes against My code here: picker.vue which receives an event named here time-picker.vue emitted events to the parent, but this event emitted by And this worked just fine before |
Check this out. Codesandbox, I have attached a link to a reproducible demo indicates the breaking change of event names had impact on my project. Steps to reproduce.
Some screenshots: Step 1Step 2Step 3Step 4 |
This may not be the issue that everyone else is having, but I was getting this message because I was using Here is a snippet from the parent component where I added it in:
|
Thanks ! That's the solution ! :) |
Version
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.
parent component:
What is expected?
The warning should not appear.
What is actually happening?
A warning appears.
Events work fine.
The text was updated successfully, but these errors were encountered: