简体   繁体   English

如何在Vue 2中循环遍历对象数组和嵌套对象

[英]How to loop through an array of objects and nested object in vue 2

I have an array that contains lots of objects and nested objects. 我有一个包含很多对象和嵌套对象的数组。 I want to loop through the array using v-for in vue 2 app. 我想在vue 2应用中使用v-for遍历数组。

Here is what I get if I print the complete array 这是我打印完整阵列时得到的结果

[
[
{
  "id": 1,
  "title": "Dolor assumenda officiis.",
  "joke": "Esse quia non voluptas facere odio id. Aut animi vero qui corporis alias. Sunt omnis qui sunt est officia.",
  "created_at": "Jun 22, 2017",
  "creator": {
    "data": {
      "id": 1,
      "name": "Dr. Sage Braun I",
      "email": "theller@example.com",
      "joined": "Jun 22, 2017"
    }
  }
},
{
  "id": 2,
  "title": "Quod occaecati doloribus amet voluptatem.",
  "joke": "Voluptas nam harum voluptatem ipsam tempora rerum. Sunt quis nam debitis. Voluptatibus id dolor quia aut odio. Omnis saepe harum quibusdam in dolorem. Possimus voluptatem impedit sed inventore fugit omnis culpa.",
  "created_at": "Jun 22, 2017",
  "creator": {
    "data": {
      "id": 1,
      "name": "Dr. Sage Braun I",
      "email": "theller@example.com",
      "joined": "Jun 22, 2017"
    }
  }
}
]
]

This is how I am trying to get the data but it does not load anything 这就是我试图获取数据但不加载任何内容的方式

<div class="row" v-for="u in users" >
     {{ u.id}}
 </div>

You seem to have a nested array. 您似乎有一个嵌套数组。 Try 尝试

<div class="row" v-for="u in users[0]" >
     {{ u.id}}
 </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM