defineModel default value is NOT reactive, buts that's odd #14350
Replies: 2 comments
-
|
@yooouuri this is by design. when you do the fix is to wrap the default in const state = defineModel<{ phone_number: string }>('lookup', {
default: () => reactive({ phone_number: '' })
})this makes the inner object a reactive proxy, so property mutations are tracked. the factory function is required (same as standard Vue props). this was confirmed as expected behavior in vuejs/core#10009. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @yooouuri! Working with Vue reactivity system and compilers can sometimes present interesting edge cases. A few quick things to consider regarding this topic:
I highly recommend checking out the Vue DevTools extension to inspect the component tree and verify if the state is updating as expected. Let me know if you want to dig deeper into the specific component logic. Hope this points you in the right direction! Let me know how it goes. Happy coding! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I have a component, where I need to use the v-model in a scenario and one I don't.
And then in my component, I bind the
stateto some form component.In scenario 1, where I bind the v-model to my component, everything is working fine.
In scenario 2, I don't need to bind the v-model, I want to use the defineModel and need the default value.
As per #10009, it states I should wrap it in
reactive. That works.This feels weird, because of the use-case that you can use defineModel as a "standalone" ref, but if I define a default value, the defineModel is not reactive anymore...
Beta Was this translation helpful? Give feedback.
All reactions