Subscribe on changes!

v-model.number modifier doesn't work on custom component

avatar
Oct 7th 2020

Version

3.0.0

Reproduction link

https://codepen.io/gilian1993/pen/XWKWjZY?editors=1111

Steps to reproduce

1: Open codepen link 2: Add a number to the fisrt input and the type "number" will display. This is a normal input. 3. Add a number to the second input and the type "string" will display. This is a custom input.

What is expected?

The custom input should return a number.

What is actually happening?

It returns a string.

avatar
Oct 7th 2020

you can get the value of modelModifiers as prop, and turn value into number inside the component.

a bad example:

app.component('custom-input', {
  props: ["modelValue", "modelModifiers"],
  template: `<input :value="modelValue" @input="$emit('update:modelValue', modelModifiers.number ? Number($event.target.value) : $event.target.value)"/>
`
})
avatar
Oct 7th 2020
avatar
Oct 9th 2020

you can get the value of modelModifiers as prop, and turn value into number inside the component.

a bad example:

app.component('custom-input', {
  props: ["modelValue", "modelModifiers"],
  template: `<input :value="modelValue" @input="$emit('update:modelValue', modelModifiers.number ? Number($event.target.value) : $event.target.value)"/>
`
})

This does work, however this is more like a workaround I hope?

avatar
Jan 26th 2023

git

Dude just change this syntax