[Vuejs]-Iterating over keys instead of values Vue app

0πŸ‘

βœ…

If the JSON response looks exactly like this:

{"id":1,"balance":10.0,"exposure":7.0,"free_funds":80.0}

Then you don’t even need the v-for because there is only one thing to iterate over.

If you want a v-for, force the data to come back as an array by wrapping it so that it would be this:

[ {"id":1,"balance":10.0,"exposure":7.0,"free_funds":80.0} ]

So:

return { results: [res.data] };

0πŸ‘

See the docs

 <li v-for="(result, key) in results" :key="result">
      <p>{{ result }} {{ key }}</p>
 </li>

Leave a comment