20
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vuetifyのv-selectにてitemsのキーがtextとvalueじゃないときの対処法

Last updated at Posted at 2019-11-29

はじめに

vuetifyjsのv-selectでは、デフォルトのitemsの仕様は以下となっています

{
  text: string | number | object
  value: string | number | object
}

itemsにtextとvalueがないときの設定に迷ったので、備忘録を兼ねてメモを残します

対処法

itemsとして、以下のオブジェクトを使用する場合のコード例です

{
  [
    { categoryName: "カテゴリ1", id: 1 },
    { categoryName: "カテゴリ2", id: 2 },
    { categoryName: "カテゴリ3", id: 3 },
    { categoryName: "カテゴリ4", id: 4 }
  ]
}

textにcategoryName、valueにidを使用する場合、v-selectのitem-valueとitems-textにitemsの対応するキーを指定します。ここでは以下のようにします

  • text : categoryName
  • value : id
<v-select
  v-model="id"
  label="*カテゴリ名"
  :items="categories"
  item-text="categoryName"
  item-value="id"
  required>
</v-select>

参考

Select component

20
12
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
20
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?