<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Vue自学:v-on遍历数组和对象</title>
</head>
<body>
<div id="app">
<!-- v-for使用数组方式进行遍历,item代表值,index代表键 -->
<ul>
<li v-for="(item,index) in obj">{{item}}</li>
</ul>
<!-- v-for使用对象方式进行遍历,value代表值,item代表键,index代表索引序列 -->
<ul>
<li v-for="(value,item,index) in info">value={{value}} || item={{item}} || index = {{index}}</li>
</ul>
</div>
</body>
<script type="text/javascript">
const app = new Vue({
el:’#app’,
data:{
//数组写法 arr:[‘value’,’value’]
obj:[‘a’,’b’,’c’,’d’,’f’,’g’],
//对象写法 obj:{name:’value’,key:’value’}
info:{
name:’wo’,
height:’170cm’,
}
}
})
</script>
</html>