You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that destructuring props in <script setup>retains reactivity in Vue 3.5+, it opens the door for a more elegant syntax for prop-modeling. I'd like to propose extending the defineProps macro to support defineModel-like behavior when destructuring into a ref.
const{ text =ref('')}=defineProps<{text: string}>();
Under the hood, the macro would infer that text is a model because:
It's a ref
It came from defineProps
Why?
Cleaner, more idiomatic syntax
Less macro sprawl (defineModel becomes unnecessary in many cases)
Reduces boilerplate while remaining explicit
The API for using the ref remains the same (text.value = 'Hello world').
Aligns with the new prop destructuring improvements
Why Not?
The only real downside is additional magic in an already magical part of Vue. But given that defineProps already has macro behaviors, this feels consistent with its trajectory—and arguably more intuitive for developers familiar with both props and v-model.
Closing
This is a small tweak that could make the developer experience smoother, especially in components that heavily use v-model. Eager to hear everyone’s feedback!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
Now that destructuring props in
<script setup>
retains reactivity in Vue 3.5+, it opens the door for a more elegant syntax for prop-modeling. I'd like to propose extending thedefineProps
macro to supportdefineModel
-like behavior when destructuring into aref
.Example
Instead of this:
We could write:
Under the hood, the macro would infer that
text
is a model because:ref
defineProps
Why?
defineModel
becomes unnecessary in many cases)text.value = 'Hello world'
).Why Not?
The only real downside is additional magic in an already magical part of Vue. But given that
defineProps
already has macro behaviors, this feels consistent with its trajectory—and arguably more intuitive for developers familiar with both props andv-model
.Closing
This is a small tweak that could make the developer experience smoother, especially in components that heavily use
v-model
. Eager to hear everyone’s feedback!Beta Was this translation helpful? Give feedback.
All reactions