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.

Make a work correct with v-models without arguments in form components

See original GitHub issue

This 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:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
07akionicommented, Oct 15, 2021

Not using modelValue is by design. The so called modelValue has no semantic meaning and could be ambiguous (both in API design level and implementation level.)

Explicit is better than impilicit.

0reactions
07akionicommented, Oct 16, 2021

Maybe you are right, I didn’t test it, in vue2 was “model” option where can modify event and value names… Perhaps in vue3 it’s impossible. Sorry for disturb. Its a habit from vue2 to use v-model

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.

Read more comments on GitHub >

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

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