码迷,mamicode.com
首页 > 其他好文 > 详细

v-for实现循环嵌套

时间:2019-01-09 01:19:40      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:set   style   round   .project   vue2   value   splay   content   name   

 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>
View Code

这个原理很简单,先使用v-for循环外层数据,然后再次循环就可以了,这个看代码就可以知道了,就不啰嗦了

v-for实现循环嵌套

标签:set   style   round   .project   vue2   value   splay   content   name   

原文地址:https://www.cnblogs.com/wikina/p/10242209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!