博客列表 >Vue自学:v-on遍历数组和对象

Vue自学:v-on遍历数组和对象

梁凯达的博客
梁凯达的博客原创
2021年01月10日 21:41:541634浏览

<!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>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议