How about same-name shorthands for events as well, aka. @my-event #14066
Replies: 1 comment 1 reply
-
|
To some extent it is already possible to use the <script setup>
function onClick() {
// ...
}
</script>
<template>
<button :onClick>Save</button>
</template>Or to use an object with <script setup>
function onClick() {
// ...
}
</script>
<template>
<button v-bind="{ onClick }">Save</button>
</template>That second example can also be adapted to work with <script setup>
function click() {
// ...
}
</script>
<template>
<button v-on="{ click }">Save</button>
</template>Here are all three of those examples combined into a Playground: Part of the reasoning behind introducing the same-name shorthand was that it was common to have things like For events that's significantly less common. An event is typically named after something that has already happened in the child, which often doesn't work so well as a function name in the parent. It's much more common to have something like But perhaps Unfortunately, there's a bigger problem... Consider this code: <form @submit.prevent>This is a fairly common usage, used to prevent a form from submitting. There is no handler here, it just needs to prevent the default action. If we introduced a shorthand for events then this would now be short for |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The recent introduction of same-name shorthands for component props is amazing, aka we can now do
instead of
which improves readability and code style.
How about the same for events, aka
instead of
IMO this would improve consistency and simplify passing events up the tree when necessary, e.g. if template refs are involved.
Beta Was this translation helpful? Give feedback.
All reactions