D
D
devilsD2018-07-22 00:16:31
Vue.js
devilsD, 2018-07-22 00:16:31

How to get object key in v-for?

There is a data object:

data: {
key1: value1,
key2: value2,
...
}

DOM shaping:
<ul>
  <li :some-data="key" v-for="item in data">{{item}}</li>
</ul>


How to insert values ​​from data (key1, key2 ...) instead of key :some-data="key"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-07-22
@devilsD

Have you tried looking at the documentation ?

<li v-for="(val, key) in data" :some-data="key">{{ val }}</li>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question