Answer the question
In order to leave comments, you need to log in
How to refer to one of the elements of the list?
Made this list:
new Vue({
el: '#masthead',
data() {
return {
list: [
{id: 0, name: 'name-1'},
{id: 1, name: 'name-2'},
{id: 2, name: 'name-3'},
{id: 3, name: 'name-4'},
{id: 4, name: 'name-5'}
]
}
},
})
#masthead
.content(v-for="item in list" data-title= вывести сюда)
h1 или сюда
<div id="masthead">
<div
class="content"
v-for="item in list"
:key="item.id"
:data-title="item.name">
<h1>{{ item.name }}</h1>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
list[0].name, list[1].name...
Or display each element in turn where you need:
list.map(item, k => {
<h1 key={k + item.id}>{item.name}</h1>
})
//Можно с условием: //
list.map(item, k => {
if(item.id === 3) {
<h1 key={k + item.id}>{item.name}</h1>
} else {
null **(something else)**
}
})
{{ header(1) }}
methods: {
header(id) {
let el = this.list.find((item) => {
return item.id === id
})
return el.name
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question