html代码

<div id="app">
    
        <!-- 数组 -->
        <ul>
          <li v-for="(item, index) in list" :key="item.id">
            {{ item.name }} - {{ index }}
          </li>
        </ul>
    
        <!-- 对象 -->
        <ul>
          <li v-for="(value, key, index) in userInfo" :key="index">
            {{ value }} - {{ key }} - {{ index }}
          </li>
        </ul>
    
        <!-- 数字 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]-->
        <ul>
          <li v-for="(item, index) in 10">
            {{ item }} - {{ index }}
          </li>
        </ul>
      </div>

js配置

<script>
    let vm = new Vue({
      el: '#app',

      data: {
        list: [
          {id: 1, name: 'Apple'},
          {id: 2, name: 'Banana'},
          {id: 3, name: 'Orange'}
        ],

        userInfo: {
          username: '张三',
          age: 18
        }
      },
    })
  </script>
Last modification:November 29th, 2019 at 02:40 pm
如果觉得我的文章对你有用,请随意赞赏