3 ms·
My brain is too smooth to grok this. This calls a referenced function: @click="addFruit" This executes an expression: @click="images.pop()" What if
by orangepanda 3y ago
My brain is too smooth to grok this.
This calls a referenced function:
@click="addFruit"
This executes an expression:
@click="images.pop()"
What if I have a expression that returns a function that should be called?
- tipiirai 3y agoThis the same as in standard JavaScript DOM event call. If you want to call a returned function in JS, you can do: <button onclick="getFunction()()">. Similar behaviour in Vue (and Nue)
- orangepanda 3y agoIts a typo then? onclick="addFruit" is not the same as onclick="addFruit()"
- tipiirai 3y agoThe onclick="addFruit" calls an instance method between the inner script tags. Similar to how JS would call a global window.addFruit with a similar syntax.
- orangepanda 3y agoKeyword being "similar", as in, not the same. Its neither the behaviour of html onclick attribute, nor dom onclick attribute.
- jefozabuss 3y agoIt's using the event listener properties like "onclick" or "onload" as "@" gets replaced with "on" in the code from what I see so you will have this more oldschool event handling: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#other_event_listener_mechanisms https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Bu... it also has some additional things here:https://github.com/nuejs/nuejs/blob/a5c844494852cdbe3282fdc588ca81742f39b56e/src/nue.js#L143 https://github.com/nuejs/nuejs/blob/a5c844494852cdbe3282fdc5... so might not work the same way, didn't spend much time to check it just a glance.