question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

You cannot v-model a `reactive()` value directly

See original GitHub issue

Describe 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

  1. Open Playground: https://formkit.link/d3506792267c1eb4909331f1695d288c
  2. Enter something in the first field -> most likely nothing will happen or only first 1-2 letters will be output above the field.
  3. Enter something in the second field -> the input is displayed almost immediately (as expected) and also the input from the first field is shown.
  4. 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
justin-schroedercommented, Feb 3, 2022

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 on ref.value instead of the ref 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).

0reactions
justin-schroedercommented, Jul 13, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found