How to set a default value to input with a v-model via HTML?
<input value="default value here"/>
Just that, as you guys know, Vue ignores the default value property when using v-model, i would like to know how can i set it via HTML?
It's necessary when i want make a "edit" page and show all predefined values of the inputs, for example
As i said in the post, vue ignores default value when using v-model, is not possible change it dynamically too, we get this error:
Error message: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value.
It's hard to help you without the bigger picture, but that error means you're passing a prop to v-model, which is invalid because you cannot mutate a prop. You need to assign your prop value to a data property and pass that data property to the v-model.
Example
// In your script section
// ...
props: ['yourProp'],
data() {
return {
yourMutableVar: yourProp
}
}
// ...
// In your template
<input v-model="yourMutableVar">