原文链接:https://www.runoob.com/vue2/vue-loop.html
1、demo代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue循环指令之v-for测试实例</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<p>Vue循环指令之v-for测试实例,每个数据之间使用下划线隔开</p>
<ul>
<template v-for="site in sites">
<li>{{ site.name }}</li>
<li>--------------</li>
</template>
</ul>
</div>
<script>
new Vue({
el: '#app',
data: {
sites: [
{ name: '对象数据name1' },
{ name: '对象数据name2' },
{ name: '对象数据name3' }
]
}
})
</script>
</body>
</html>
2、页面效果
3、使用总结
v-for指令用于实现数据的循环访问,语法为<template v-for="site in sites">
,上面的例子中,每一次循环数据,都会输出一个列表标签。