template doesn't call returned function. why? #12267
Replies: 4 comments 7 replies
-
You could interpret The return value happens to be another function, but:
You could expect Vue to call it automatically (if it's callable), but that would be a strange behavior, because:
To avoid confusion, I suggest to define the <button @click="() => go2('hello')">2</button> to make the code reflect what's happening more clearly and to differentiate it from what is happening on button 1. |
Beta Was this translation helpful? Give feedback.
-
The issue is that Solution
|
Beta Was this translation helpful? Give feedback.
-
Maybe the article on Event Handling in the Vue docs can help.
In the code you provided, the first button is clearly case 2 - you point to the function to be executed which is defined in the Now to answer your question: The second button is not a method handler. You are not pointing to a function to be executed, you are just providing a Javascript expression there. And in that Javascript expression, you only call |
Beta Was this translation helpful? Give feedback.
-
Hi @modelair , In Vue, the issue here revolves around how
SolutionTo ensure that <button @click="e => go2('hello')(e)">2</button> This approach ensures that the inner function returned by |
Beta Was this translation helpful? Give feedback.
-
play.vuejs.org
Hello. Why second button doesn't call returned function? it's a bug or a feature?
i guess it does
of course i saw what happens in rendered code. but why?
Beta Was this translation helpful? Give feedback.
All reactions