Skip to content

Should v-model-* directives be public? #156

Closed
@jods4

Description

@jods4

In this comment Evan pointed out to me that vModelText (and friends) is exported for the compiler only and is not public nor documented.

Unless I miss something, this has an unfortunate consequence: you can't write a JS render function that binds v-model of an input.

Because this template:

<input v-model="name">

is compiled into the JS equivalent of this by the compiler:

<input v-model-text="name" @update:modelValue="name = $event">

and you can't do that transformation in user code if v-model-text is off-limits.

Alternatives

  1. Use undocumented apis 🤞
    Drawback: risks breaking at any minor release.

  2. Re-implement v-model yourself by compiling

<input :value="name" @input="name = $event.target.value">

Drawback: this is not trivial when implementing more complex features, such as modifiers v-model.trim, or other models e.g. v-model-checkbox with an array.

  1. Create a micro-component with compiler and re-use it in your render function.:
<input v-model="$props.name" v-bind="$attrs">

Drawback: far from pretty.

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