3
0

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

この度Vue.jsを学び始めました。
その勉強内容をまとめます

v-for

HTML要素を繰り返し表示する時にv-forを使います。

Vue.js

//配列から順番に値を1つづつ取り出し表示する
<タグ v-for="変数 in 配列>

//指定した回数表示を繰り返す
<タグ v-for="変数 in 最大値>

//配列から値と番号を1つずつ取り出し表示する
タグ v-for="(変数,番号) in 配列">

使い方

Vue.js
//配列から1つずつ取り出す使い方

<div id="app">
  <ul>
    <li v-for="item in Array">{{ item }}</li>
  </ul>
</div>

<script>
  new Vue({
    el: '#app',
    data: {
      Array:['いちご','メロン','バナナ','りんご']
    }
  })
</script>

上記のではArrayという配列にdataで配列データを用意しておき、それをv-forで順番に取り出し{{ item }}に入れて出力しています。

以下のようにすると配列データを番号付きで出力することもできます。

Vue.js
//配列から1つずつ取り出し、番号付きで表紙する

<div id="app">
  <ul>
    <li v-for="(item,index) in Array">{{ index }}:{{ item }}</li>
  </ul>
</div>

<script>
  new Vue({
    el: '#app',
    data: {
      Array:['いちご','メロン','バナナ','りんご']
    }
  })
</script>

以上です。

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?