I have recently made the switch from React to Vue and I am really impressed by the v-model
feature that Vue offers. However, I am now facing a dilemma and struggling to figure out the best way to handle this situation in a more Vue-appropriate manner.
This is the structure of my component tree:
- FormContainer
-FormView
- CustomInput
- input
My state is residing in FormContainer
, let's say we have properties like name and age. I want to find a solution without resorting to custom setter methods, similar to how I would use v-model
. How can I efficiently pass the data down to the input component?
Currently, I have implemented it as follows:
// within my container
<form-view :name="name" :age="age" />
// within my form view, I have something like
<custom-input v-model="age"/>
<input v-model="name" />
Unfortunately, both approaches are not working as expected, resulting in an error stating Avoid mutating a prop directly
.
I wish to achieve something like:
<form-view @age="age" :age="age" @name="name" :name="name"/>
or a similar approach. Please advise if you need further clarification on this matter.