You cannot v-model a `reactive()` value directly
See original GitHub issueDescribe the bug
When (v-model) binding a reactive() object to the <FormKit type="form">
, it will loose it’s reactivity almost completely.
Using a ref() instead is working and even updates the reactive object when changed.
The examples in the documentation use ref(), but I’m wondering whether reactive shouldn’t work as well, since it’s common to use reactive() for objects.
Reproduction
- Open Playground: https://formkit.link/d3506792267c1eb4909331f1695d288c
- Enter something in the first field -> most likely nothing will happen or only first 1-2 letters will be output above the field.
- Enter something in the second field -> the input is displayed almost immediately (as expected) and also the input from the first field is shown.
- Repeat the same with the third field -> again no updates, only after the middle input is changed.
Desktop
- OS: Mac 11.6.2
- Browser: Chrome 98.0.4758.80
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Vue 3 pass reactive object to component with two way binding
The message variable in the parent component cannot be a reactive() and must be a ref() . When the v-model receives the newly...
Read more >when use custom v-model (with <script setup> style),it goes ...
In your example, you use v-model="modelValue" , which is not allowed - you can't mutate props. This is likely the root cause of...
Read more >V-Model in Vue3 | Evan's Blog
V -Model in Vue3. By using Vue's new Composition API, it feels like Vue's reactivity system has been freed of the constraints of...
Read more >Reactivity Fundamentals - Vue.js
With Options API, we use the data option to declare reactive state of a component. The option value should be a function that...
Read more >What you should know about Vue v-model - LearnVue
How to use v-model for two-way data binding between two components. ... the input changes and the new value cannot be parsed by...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @tosling 👋
Thanks for the quality report! It turns out what you’re trying to do is not a supported feature of Vue 3 itself — that is — directly v-modeling a
reactive()
object. You can model on a property of a reactive object (yourReactiveObject.formValues
), but not the object itself since that would causes whole-sale replacement of the actual object. That’s why a ref works, because it is actually operating onref.value
instead of theref
itself.Perhaps, if there is any action to take here, we could throw an helpful exception for users who make the same mistake (Ive done it myself a few times).
Closing this issue as it won’t be resolved at the FormKit level and we now have some warnings in the docs to help users avoid it.