判断循环两兄弟基本是不能少,为了支持当前的循环,我们可以弄个数组。
测试数据网站
https://www.json-generator.com/
模板代码
[
'{{repeat(5, 7)}}',
{
age: '{{integer(20, 40)}}',
name: '{{firstName()}} {{surname()}}',
gender: '{{gender()}}',
company: '{{company().toUpperCase()}}',
email: '{{email()}}',
phone: '+1 {{phone()}}',
address: '{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}'
}
]
测试数据
[
{
"age": 33,
"name": "Vance Lyons",
"gender": "male",
"company": "COMVEY",
"email": "vancelyons@comvey.com",
"phone": "+1 (916) 416-2139",
"address": "916 Vermont Court, Siglerville, Idaho, 9141"
},
{
"age": 26,
"name": "Rosalind Hamilton",
"gender": "female",
"company": "COMVENE",
"email": "rosalindhamilton@comvene.com",
"phone": "+1 (989) 488-2329",
"address": "147 Wallabout Street, Hemlock, Maryland, 2591"
},
{
"age": 33,
"name": "Greta Blake",
"gender": "female",
"company": "DIGITALUS",
"email": "gretablake@digitalus.com",
"phone": "+1 (988) 539-3097",
"address": "226 Denton Place, Chemung, Colorado, 6521"
},
{
"age": 32,
"name": "Lester Perez",
"gender": "male",
"company": "BLURRYBUS",
"email": "lesterperez@blurrybus.com",
"phone": "+1 (946) 422-2734",
"address": "263 Beacon Court, Benson, Oregon, 4107"
},
{
"age": 33,
"name": "Goldie Gibson",
"gender": "female",
"company": "ECOSYS",
"email": "goldiegibson@ecosys.com",
"phone": "+1 (822) 479-2602",
"address": "963 McClancy Place, Escondida, Pennsylvania, 9949"
},
{
"age": 40,
"name": "Adele Rodriguez",
"gender": "female",
"company": "ZYTREK",
"email": "adelerodriguez@zytrek.com",
"phone": "+1 (989) 494-3224",
"address": "350 Calyer Street, Delwood, New Hampshire, 9314"
},
{
"age": 22,
"name": "Roseann Mcknight",
"gender": "female",
"company": "ZAGGLES",
"email": "roseannmcknight@zaggles.com",
"phone": "+1 (918) 518-2722",
"address": "522 Hutchinson Court, Morgandale, South Dakota, 8764"
}
]
循环demo
vue使用v-for进行循环,让表格好看点,引入bulma.css。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../lib/bulma.css">
</head>
<body>
<div id="app" class="container">
<table class="table is-bordered is-striped">
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>邮箱</th>
<th>电话</th>
<th>地址</th>
</tr>
</thead>
<tbody>
<tr v-for="girl in girls">
<td>{{girl.name}}</td>
<td>{{girl.age}}</td>
<td>{{girl.gender}}</td>
<td>{{girl.email}}</td>
<td>{{girl.phone}}</td>
<td>{{girl.address}}</td>
</tr>
</tbody>
</table>
</div>
<script src="../lib/vue.js"></script>
<script>
var vm = new Vue({
el:'#app',
data:{
girls:[
{
"age": 33,
"name": "Vance Lyons",
"gender": "male",
"company": "COMVEY",
"email": "vancelyons@comvey.com",
"phone": "+1 (916) 416-2139",
"address": "916 Vermont Court, Siglerville, Idaho, 9141"
},
{
"age": 26,
"name": "Rosalind Hamilton",
"gender": "female",
"company": "COMVENE",
"email": "rosalindhamilton@comvene.com",
"phone": "+1 (989) 488-2329",
"address": "147 Wallabout Street, Hemlock, Maryland, 2591"
},
{
"age": 33,
"name": "Greta Blake",
"gender": "female",
"company": "DIGITALUS",
"email": "gretablake@digitalus.com",
"phone": "+1 (988) 539-3097",
"address": "226 Denton Place, Chemung, Colorado, 6521"
},
{
"age": 32,
"name": "Lester Perez",
"gender": "male",
"company": "BLURRYBUS",
"email": "lesterperez@blurrybus.com",
"phone": "+1 (946) 422-2734",
"address": "263 Beacon Court, Benson, Oregon, 4107"
},
{
"age": 33,
"name": "Goldie Gibson",
"gender": "female",
"company": "ECOSYS",
"email": "goldiegibson@ecosys.com",
"phone": "+1 (822) 479-2602",
"address": "963 McClancy Place, Escondida, Pennsylvania, 9949"
},
{
"age": 40,
"name": "Adele Rodriguez",
"gender": "female",
"company": "ZYTREK",
"email": "adelerodriguez@zytrek.com",
"phone": "+1 (989) 494-3224",
"address": "350 Calyer Street, Delwood, New Hampshire, 9314"
},
{
"age": 22,
"name": "Roseann Mcknight",
"gender": "female",
"company": "ZAGGLES",
"email": "roseannmcknight@zaggles.com",
"phone": "+1 (918) 518-2722",
"address": "522 Hutchinson Court, Morgandale, South Dakota, 8764"
}
]
}
})
</script>
</body>
</html>
效果
如果在数组当中加入一个对象,就会发生改变了。
对象数据
{
"age": 29,
"name": "Lena Grant",
"gender": "female",
"company": "ARTIQ",
"email": "lenagrant@artiq.com",
"phone": "+1 (857) 416-2646",
"address": "876 Tehama Street, Blandburg, South Dakota, 5464"
}