1. <html>
    2. <head>
    3. <style>
    4. .pclass{
    5. color:red;
    6. margin-bottom: 20px;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <div id="app">
    12. <p class="pclass"> 1.普通for:</p>
    13. <ul>
    14. <li v-for="a in values">当前数据:{{a}}</li>
    15. </ul>
    16. <p class="pclass"> 2.普通for带slice:</p>
    17. <ul>
    18. <li v-for="a in values.slice(0, 2)">当前数据:{{a}}</li>
    19. </ul>
    20. <p class="pclass"> 3.带下标的for,和通过下标进行获致:</p>
    21. <div v-for="(a,i) in values":key="i"> 当前数据:{{a}},数组读取:{{values[i]}},下标:{{i}} </div>
    22. <p class="pclass"> 4.遍历对象:</p>
    23. <ul>
    24. <li v-for="(v,k,i) in student">
    25. value:{{v}},key:{{k}},下标:{{i}}
    26. </li>
    27. </ul>
    28. <p class="pclass"> 5.嵌套遍历数组对象:</p>
    29. <ul>
    30. <li v-for="(student,i) in students">
    31. <span> student:{{student}},下标:{{i}} </span>
    32. </br>
    33. <span v-for="(v,k,j) in student"> 下标:{{j}},value:{{v}},key:{{k}} </br> </span>
    34. </li>
    35. </ul>
    36. </div>
    37. </body>
    38. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    39. <script>
    40. new Vue({
    41. //指定作用于那一个div
    42. el:'#app',
    43. //属性
    44. data:{
    45. values:[1,2,3,3,4,5],
    46. student:{
    47. name:'xiaoming',
    48. age:18
    49. },
    50. students:[
    51. {name:'xiaoming',age:18},
    52. {name:'xiaoli',age:20}
    53. ]
    54. }
    55. });
    56. </script>
    57. </html>