LoginSignup
0
2

More than 3 years have passed since last update.

Vue3 v-modelの仕様

Last updated at Posted at 2020-10-15

v-modelに使用するデフォルトのprop名とイベントが変更になっています

Vue2.x

SomeComponent.vue
// valueのpropで受け取り
props: [value]
// onInputで返却
this.$emit('input', updatedValue)
<some-component v-model="hoge" />
// ↑は↓と等価
<some-component :value="hoge" onInput="(val) => hoge = val"/>

Vue3

SomeComponent.vue
// modelValueのpropで受け取り
props: [modelValue]
// onUpdate:modelValueで返却
context.emit('update:modelValue', updatedValue)
<some-component v-model="hoge" />
// ↑は↓と等価
<some-component :modelValue="hoge" onUpdate:modelValue="(val) => hoge = val"/>

Vue3別例

SomeComponent.vue
// modelValue以外もつかえる
props: [foobar]
// onUpdate:propnameで返却
context.emit('update:foobar', updatedValue)
// modelValue以外のpropにv-modelで双方向バインドする場合は明示が必要
<some-component v-model:foobar="hoge" />
// ↑は↓と等価
<some-component :foobar="hoge" onUpdate:foobar="(val) => hoge = val"/>

ref https://github.com/vuejs/rfcs/blob/master/active-rfcs/0011-v-model-api-change.md

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2