v-for实现循环嵌套
Posted wikina
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了v-for实现循环嵌套相关的知识,希望对你有一定的参考价值。
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <title></title> 6 <meta charset="UTF-8"> 7 <meta name="viewport" content="width=device-width, initial-scale=1"> 8 <script src="./js/vue2.js"></script> 9 </head> 10 11 <body> 12 <div id="app"> 13 <ul> 14 <!-- 先从origin获得对应的数据 --> 15 <li v-for="(value,index,key) in origin"> 16 {{value.info}} 17 <!-- 在根据从origin获得的数据遍历对应的对象 --> 18 <ul> 19 <li v-for="items in value.project"> 20 {{items}} 21 </li> 22 </ul> 23 </li> 24 </ul> 25 </div> 26 <script> 27 var vm = new Vue({ 28 el: ‘#app‘, 29 data: { 30 origin:[ 31 { 32 info:"all", 33 "project":{"name":"wikina","age":"20","birthday":"1996"}, 34 }, 35 { 36 info:"all", 37 "project":{"name":"wikina","age":"20","birthda":"1996"}, 38 }, 39 { 40 info:"all", 41 "project":{"name":"wikina","age":"20","birthda":"1996"}, 42 } 43 ] 44 45 } 46 }) 47 </script> 48 </body> 49 50 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <title></title> 6 <meta charset="UTF-8"> 7 <meta name="viewport" content="width=device-width, initial-scale=1"> 8 <script src="./js/vue2.js"></script> 9 </head> 10 11 <body> 12 <div id="app"> 13 <ul> 14 <!-- 先从origin获得对应的数据 --> 15 <li v-for="(value,index,key) in origin"> 16 {{value.info}} 17 <!-- 在根据从origin获得的数据遍历对应的对象 --> 18 <ul> 19 <li v-for="items in value.project"> 20 {{items}} 21 </li> 22 </ul> 23 </li> 24 </ul> 25 </div> 26 <script> 27 var vm = new Vue({ 28 el: ‘#app‘, 29 data: { 30 origin:[ 31 { 32 info:"all", 33 "project":{"name":"wikina","age":"20","birthday":"1996"}, 34 }, 35 { 36 info:"all", 37 "project":{"name":"wikina","age":"20","birthda":"1996"}, 38 }, 39 { 40 info:"all", 41 "project":{"name":"wikina","age":"20","birthda":"1996"}, 42 } 43 ] 44 45 } 46 }) 47 </script> 48 </body> 49 50 </html>
这个原理很简单,先使用v-for循环外层数据,然后再次循环就可以了,这个看代码就可以知道了,就不啰嗦了
以上是关于v-for实现循环嵌套的主要内容,如果未能解决你的问题,请参考以下文章