I have been trying to learn how Vue's v-model works with custom input and also regular input components.
I have seen examples where v-model
is tied to a value in the component and also in the template and both of these values will be different. I find this very confusing and I think it may be a misunderstanding of "two way binding". How do you have an input tied to two values.
Example:
//v-model in template
const myCustomInput = ('my-custom-input', {
data() {
return {
myObj: 'hello'
}
},
template: `<input v-model="myObj" >`
});
//v-model in component
<my-custom-input v-model="someOtherObj.str">
I have seen examples of having two v-models like this with different values both defined at the template level and component.
However, when looking at this SO post, the answer by @asemahle seems a lot more logical. Furthermore the official Vue docs does not even have 2 separate v-models on the template and the component Vue JS component basics
In the latter examples, it seems a lot more logical as there is only one v-model defined and tied to the input component rather than two.
Is the first example incorrect? And if it's not can someone explain more clearly how that works. I can't seem to find any real good documents on having two separate v-models
for one input.