Skip to content

v-model.sync to automatically emit a prop's changes as an event #8403

Closed
@dylanized

Description

@dylanized

What problem does this feature solve?

v-model is a helpful tool, but it doesn't work in nested components. Instead we are supposed to use v-model on a parent component, then manually bind props and manually emit a change event within the child component. This is too verbose.

Instead, I am proposing an option for v-model that automatically emits the change event.

What does the proposed API look like?

Template for the parent component:

<div>
  <custom-input v-model='foo'></custom-input>
</div>

Template for the child component:

<div>
  <input type='text' v-model.sync='foo' />
</div>

AS AN ALTERNATIVE TO:

Template for the parent component:

<div>
  <custom-input v-model='foo'></custom-input>
</div>

Template for the child component:

<div>
  <input type='text' :value='foo' @input='$emit("input", $event.target.value)' />
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions