Vue: When using v-model on a component element, the `value` prop is always a String

Created on 29 Jun 2016  路  2Comments  路  Source: vuejs/vue

Vue.js version

v2.0.0-alpha.8

Reproduction Link

https://jsfiddle.net/nf02Ltct/2/

Steps to reproduce

  • open console
  • read warning

    What is Expected?

the special "value" prop which is passed from v-model on the component element in the template, shuold contain a Boolean value, since the parent passes a Boolean to v-model

What is actually happening?

[Vue warn]: Invalid prop: type check failed for prop "value". Expected Boolean, got String. (found in component: )

Suspicion:

I think it has something to do with whith this comment:

https://github.com/vuejs/vue/blob/v2.0.0-alpha.8/src/platforms/web/runtime/modules/props.js#L20-L21

bug

Most helpful comment

Fixed this, and also introduced a small breaking change: the component can now directly emit the value:

this.$emit('input', value)

Instead of

this.$emit('input', { target: { value }})

This also means when emitting the value of a native event you will need to do

this.$emit('input', e.target.value)

All 2 comments

Fixed this, and also introduced a small breaking change: the component can now directly emit the value:

this.$emit('input', value)

Instead of

this.$emit('input', { target: { value }})

This also means when emitting the value of a native event you will need to do

this.$emit('input', e.target.value)

Thanks for the quick fix.

I like the change, it fits with the usual procedure of passing event.target.value when emitting/dispatching events today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loki0609 picture loki0609  路  3Comments

franciscolourenco picture franciscolourenco  路  3Comments

bfis picture bfis  路  3Comments

hiendv picture hiendv  路  3Comments

julianxhokaxhiu picture julianxhokaxhiu  路  3Comments