判断循环两兄弟基本是不能少,为了支持当前的循环,我们可以弄个数组。

测试数据网站

https://www.json-generator.com/

模板代码

  1. [
  2. '{{repeat(5, 7)}}',
  3. {
  4. age: '{{integer(20, 40)}}',
  5. name: '{{firstName()}} {{surname()}}',
  6. gender: '{{gender()}}',
  7. company: '{{company().toUpperCase()}}',
  8. email: '{{email()}}',
  9. phone: '+1 {{phone()}}',
  10. address: '{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}'
  11. }
  12. ]

测试数据

  1. [
  2. {
  3. "age": 33,
  4. "name": "Vance Lyons",
  5. "gender": "male",
  6. "company": "COMVEY",
  7. "email": "vancelyons@comvey.com",
  8. "phone": "+1 (916) 416-2139",
  9. "address": "916 Vermont Court, Siglerville, Idaho, 9141"
  10. },
  11. {
  12. "age": 26,
  13. "name": "Rosalind Hamilton",
  14. "gender": "female",
  15. "company": "COMVENE",
  16. "email": "rosalindhamilton@comvene.com",
  17. "phone": "+1 (989) 488-2329",
  18. "address": "147 Wallabout Street, Hemlock, Maryland, 2591"
  19. },
  20. {
  21. "age": 33,
  22. "name": "Greta Blake",
  23. "gender": "female",
  24. "company": "DIGITALUS",
  25. "email": "gretablake@digitalus.com",
  26. "phone": "+1 (988) 539-3097",
  27. "address": "226 Denton Place, Chemung, Colorado, 6521"
  28. },
  29. {
  30. "age": 32,
  31. "name": "Lester Perez",
  32. "gender": "male",
  33. "company": "BLURRYBUS",
  34. "email": "lesterperez@blurrybus.com",
  35. "phone": "+1 (946) 422-2734",
  36. "address": "263 Beacon Court, Benson, Oregon, 4107"
  37. },
  38. {
  39. "age": 33,
  40. "name": "Goldie Gibson",
  41. "gender": "female",
  42. "company": "ECOSYS",
  43. "email": "goldiegibson@ecosys.com",
  44. "phone": "+1 (822) 479-2602",
  45. "address": "963 McClancy Place, Escondida, Pennsylvania, 9949"
  46. },
  47. {
  48. "age": 40,
  49. "name": "Adele Rodriguez",
  50. "gender": "female",
  51. "company": "ZYTREK",
  52. "email": "adelerodriguez@zytrek.com",
  53. "phone": "+1 (989) 494-3224",
  54. "address": "350 Calyer Street, Delwood, New Hampshire, 9314"
  55. },
  56. {
  57. "age": 22,
  58. "name": "Roseann Mcknight",
  59. "gender": "female",
  60. "company": "ZAGGLES",
  61. "email": "roseannmcknight@zaggles.com",
  62. "phone": "+1 (918) 518-2722",
  63. "address": "522 Hutchinson Court, Morgandale, South Dakota, 8764"
  64. }
  65. ]

循环demo

vue使用v-for进行循环,让表格好看点,引入bulma.css。

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <link rel="stylesheet" href="../lib/bulma.css">
  7. </head>
  8. <body>
  9. <div id="app" class="container">
  10. <table class="table is-bordered is-striped">
  11. <thead>
  12. <tr>
  13. <th>姓名</th>
  14. <th>年龄</th>
  15. <th>性别</th>
  16. <th>邮箱</th>
  17. <th>电话</th>
  18. <th>地址</th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <tr v-for="girl in girls">
  23. <td>{{girl.name}}</td>
  24. <td>{{girl.age}}</td>
  25. <td>{{girl.gender}}</td>
  26. <td>{{girl.email}}</td>
  27. <td>{{girl.phone}}</td>
  28. <td>{{girl.address}}</td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. <script src="../lib/vue.js"></script>
  34. <script>
  35. var vm = new Vue({
  36. el:'#app',
  37. data:{
  38. girls:[
  39. {
  40. "age": 33,
  41. "name": "Vance Lyons",
  42. "gender": "male",
  43. "company": "COMVEY",
  44. "email": "vancelyons@comvey.com",
  45. "phone": "+1 (916) 416-2139",
  46. "address": "916 Vermont Court, Siglerville, Idaho, 9141"
  47. },
  48. {
  49. "age": 26,
  50. "name": "Rosalind Hamilton",
  51. "gender": "female",
  52. "company": "COMVENE",
  53. "email": "rosalindhamilton@comvene.com",
  54. "phone": "+1 (989) 488-2329",
  55. "address": "147 Wallabout Street, Hemlock, Maryland, 2591"
  56. },
  57. {
  58. "age": 33,
  59. "name": "Greta Blake",
  60. "gender": "female",
  61. "company": "DIGITALUS",
  62. "email": "gretablake@digitalus.com",
  63. "phone": "+1 (988) 539-3097",
  64. "address": "226 Denton Place, Chemung, Colorado, 6521"
  65. },
  66. {
  67. "age": 32,
  68. "name": "Lester Perez",
  69. "gender": "male",
  70. "company": "BLURRYBUS",
  71. "email": "lesterperez@blurrybus.com",
  72. "phone": "+1 (946) 422-2734",
  73. "address": "263 Beacon Court, Benson, Oregon, 4107"
  74. },
  75. {
  76. "age": 33,
  77. "name": "Goldie Gibson",
  78. "gender": "female",
  79. "company": "ECOSYS",
  80. "email": "goldiegibson@ecosys.com",
  81. "phone": "+1 (822) 479-2602",
  82. "address": "963 McClancy Place, Escondida, Pennsylvania, 9949"
  83. },
  84. {
  85. "age": 40,
  86. "name": "Adele Rodriguez",
  87. "gender": "female",
  88. "company": "ZYTREK",
  89. "email": "adelerodriguez@zytrek.com",
  90. "phone": "+1 (989) 494-3224",
  91. "address": "350 Calyer Street, Delwood, New Hampshire, 9314"
  92. },
  93. {
  94. "age": 22,
  95. "name": "Roseann Mcknight",
  96. "gender": "female",
  97. "company": "ZAGGLES",
  98. "email": "roseannmcknight@zaggles.com",
  99. "phone": "+1 (918) 518-2722",
  100. "address": "522 Hutchinson Court, Morgandale, South Dakota, 8764"
  101. }
  102. ]
  103. }
  104. })
  105. </script>
  106. </body>
  107. </html>

效果

image.png

如果在数组当中加入一个对象,就会发生改变了。
对象数据

  1. {
  2. "age": 29,
  3. "name": "Lena Grant",
  4. "gender": "female",
  5. "company": "ARTIQ",
  6. "email": "lenagrant@artiq.com",
  7. "phone": "+1 (857) 416-2646",
  8. "address": "876 Tehama Street, Blandburg, South Dakota, 5464"
  9. }

image.png

image.png