O
O
Olesya_v2021-05-07 23:22:26
Vue.js
Olesya_v, 2021-05-07 23:22:26

How to parse vue array with different types?

{
  "posts": [
    {
      "id": 1,
      "title": "someTitlePost",
      "author": "someName"
    }
  ],
  "worke": [
    {
      "area": "frontend"
    }
  ],
  "comments": [
    {
      "id": 1,
      "body": "some comment",
      "postId": 1
    }
  ],
  "profile": {
    "name": "typicode"
  }
}

I parse the array like this:
<ul v-for="(link, index) in links" :key="index">
        <li>
          <strong>{{ index }}</strong>
          <ul>
            <!-- v-if="link.length >
            <li v-for="el in link" >
              
              <p v-for="(prop, index) in el" >
               
                  <span>{{ index }} :</span>
                  <span >{{ prop }} </span>
              </p>
            </li>
          </ul>
        </li>
      </ul>


BUT! Due to the fact that the last element is an object (profile), it is displayed like this:
6095a2357357e700029668.jpeg

How to solve the problem correctly, with a minimum number of actions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-05-08
@Olesya_v

with a minimum number of steps

Well, whatever you say.
Replace v-for="el in link"with v-for="el in [].concat(link)".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question