0

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.

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": "[email protected]",
      "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": "[email protected]",
      "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>
3
  • 1
    What did you try? Show your JS code so far. Commented Jun 30, 2017 at 3:24
  • you want to loop through the properties or the items in the array? Commented Jun 30, 2017 at 3:26
  • I edited the question please see the last part.. Commented Jun 30, 2017 at 3:33

1 Answer 1

1

You seem to have a nested array. Try

<div class="row" v-for="u in users[0]" >
     {{ u.id}}
 </div>
Sign up to request clarification or add additional context in comments.

1 Comment

yeah it worked I tried the same ways but I got en error before but now the same code working :) I can get the first objects using u.id and to get the id from creator object I need to use u.creator.data.id Thank you for the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.