defineModel default value is NOT reactive, buts that's odd #14350
Replies: 1 comment
-
|
@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.
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