基于源数据多次渲染元素或模板块。此指令之值,必须使用特定语法 alias in expression ,为当前遍历的元素提供别名:
<div v-for="item in items"> {{ item.text }} </div>
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue.js</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="app">
<h1>v-for循环</h1>
<!--数组下表-->
{{ characters[0] }},
{{ characters[1] }}
<ul>
<li v-for="(character,index) in characters">{{character}}</li>
</ul>
<ul>
<li v-for="(user,index) in users">{{index+1}}-{{user.name}}-{{user.age}}</li>
</ul>
<div v-for="(user,index) in users">
<h3>{{index}}.{{user.name}}.{{user.age}}</h3>
</div>
<template v-for="user in users">
<div v-for="(val,key) in user">{{key}}-{{val}}</div>
</template>
</div>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
app.js
new Vue({
el: '#app',
data: {
characters: ["Mario","luffy","yoshi"],
users: [
{name: 'Mario', age: 30},
{name: 'luffy', age: 29},
{name: 'yoshi', age: 30}
]
},
methods: {
},
computed: {
}
});
Vue系列文章目录
- vue系列文章(1):对象绑定,属性绑定
- Vue系列文章(2)事件绑定,鼠标点击事件
- vue系列文章(3):事件修饰符
- Vue系列文章(4)键盘事件及键盘修饰符
- vue系列文章(5)双向数据绑定
- vue系列文章(6)计算属性computed
- vue系列文章(7)动态CSS类型绑定
- vue系列文章(8)条件渲染
- vue系列文章(9)v-for条件循环
- vue系列文章(10)vue实战项目demo
- vue系列文章(11):初始化多个实例对象
- vue系列文章(12)初始组件的应用
- Vue系列文章(13)vue cli脚手架
- vue系列文章(14)vue-cli脚手架,组件嵌套,全局组件注册和局部组件注册
- vue系列文章(15)属性传值props
- vue系列文章(16)传值和传引用的类型和区别
- vue系列文章(17)利用事件传递将子组件值传递给父组件
- vue系列文章(18)vue生命周期
- vue系列文章(19)vue路由配置
- vue系列文章(20) vue网络请求vue-resource
如果上面文章对你有用,打赏下我吧@*@