Make a work correct with v-models without arguments in form components
See original GitHub issueThis function solves the problem (这个功能解决的问题)
v-model=“…” doesn’t work in Form components
Expected API (期望的 API)
Now form components work only if you put v-model:value=“…” tag, but v-model=“…” doesn’t work. vue can use v-model by default without argument value. For this need to add anywhere
emits: ['update:value'] //(emits: ['update:checked'] in checkox)
As described in https://v3.vuejs.org/guide/migration/v-model.html#migration-strategy
for all v-models without arguments, make sure to change props and events name to modelValue and update:modelValue respectively
export default {
props: {
modelValue: String // previously was `value: String`
},
emits: ['update:modelValue'],
methods: {
changePageTitle(title) {
this.$emit('update:modelValue', title) // previously was `this.$emit('input', title)`
}
}
}
https://v3.vuejs.org/guide/migration/v-model.html#overview
BREAKING: When used on custom components, v-model prop and event default names are changed: prop: value -> modelValue; event: input -> update:modelValue;
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Make a work correct with v-models without arguments in form ...
This function solves the problem (这个功能解决的问题). v-model="..." doesn't work in Form components. Expected API (期望的 API).
Read more >Express Tutorial Part 6: Working with forms - MDN Web Docs
While here we have included just one (text) field for entering the team name, a form may contain any number of other input...
Read more >Working with forms - Django documentation
Django provides a range of tools and libraries to help you build forms to ... (A ModelForm maps a model class's fields to...
Read more >Building a template-driven form - Angular
Template-driven forms use two-way data binding to update the data model in the component as changes are made in the template and vice...
Read more >View components in ASP.NET Core | Microsoft Learn
View components don't use model binding, they depend on the data passed when calling the view component. This article was written using ...
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 Free
Top 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
Not using
modelValue
is by design. The so calledmodelValue
has no semantic meaning and could be ambiguous (both in API design level and implementation level.)Explicit is better than impilicit.
Try to accept a new pattern. Making everything explicit will make your project more maintainable. Every other people who see your code will immediately know what you tried to do.