1
1

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.

[Vue.js]v-for

Posted at

v-forを使って配列を操作

```javascript js //データに配列を作っておきます data:{ fruits:['バナナ','りんご','びわ'] ``` ```html html
    //fruitsの中身をfruitにいれる{{}}の中身に順番にfruitをいれていく
  • {{fruit}}

```
  • バナナ
  • りんご
  • びわ

と表示される

第2引数を渡す

```html html
    ()で囲ってカンマで区切って第二引数
  • {{fruit}}

```

第2引数では配列のインデックス番号が取得できる

```html html
    //(0)バナナ のように表示される
  • ({{index}}){{fruit}}




<h1>v-forを使ってオブジェクトを操作</h1>
```javascript
js
data:{
//データにオブジェクトを作っておく
    fruits{
        yellow:'バナナ',
        red:'りんご',
        orange:'オレンジ'
    }
}   
html
   <ul>
//valueの中にオブジェクトの値を入れていく
      <li v-for = "value in fruits>{{value}}</li>
    </ul>

第2引数と第3引数で取得できるもの

配列と同じように記述できる

```html //2番目はキー、3番目はインデックス番号を取得できる  //表示させる中身はliに書く ({{index}}){{fruit}}
```
  • (0)バナナ

と表示される

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?