1
2

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.

v-forでオブジェクトを表示

Last updated at Posted at 2021-05-07

オブジェクトとは

全てのデータはオブジェクトです。配列やHash、数字や文字列も、オブジェクトです。

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<div id="app">
<ul>
<li v-for="value in object">{{ value }}</li>
</ul>
</div>
new Vue({
  el: '#app',
 data: {
   object: {
   firstName: '太郎',
   lastName: '田中',
   age: '20才'
           }
       }
})

20210507-180504.png

表し方

v-for 適当に名前をつけて(valueで) in 設定オブジェクト名

*firstName,lastName,ageがキーで太郎,田中,20才がバリューと言います。

第2引数を表現

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<div id="app">
<ul>
<li v-for="(value, key) in object">{{key}},{{ value }}</li>
           第1引数 第2引数
</ul>
</div>

20210507-180257.png

第3引数を取得

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<div id="app">
<ul>
<li v-for="(value,key,index) in object">({{index}}){{key}},{{ value }}</li>
</ul>
</div>

20210507-180806.png

1
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?