i made v-for loop cards with vue-Bootstrap.
in state, there are dummy. like this.
JavaScript
x
5
1
myTeams: [
2
{name: "T1", img: "https://placekitten.com/300/300" , nickname: "", followers: 14565, category: "lol"},
3
{name: "ManU", img: "https://placekitten.com/300/300" , nickname: "", followers: 1234, category: "football"},
4
{name: "Chelsea", img: "https://placekitten.com/300/300" , nickname: "", followers: 76567, category: "baseaball"},
5
],
and here is my vue.js code
JavaScript
1
43
43
1
<template>
2
<div>
3
<br>
4
<b-card-group columns deck>
5
<br>
6
<br>
7
<b-card
8
v-b-modal.modal-1
9
v-for="(team, idx) in myteams"
10
:key = "idx"
11
:team="team"
12
:src = "team.img"
13
border-variant="success"
14
tag="article"
15
style="max-width: 15rem;"
16
class="mb-2"
17
>
18
<b-container>
19
<b-avatar
20
:src="team.img"
21
size="6rem"
22
class="d-flex"
23
>
24
</b-avatar>
25
<br>
26
<b-card-title>
27
<div v-if="team.nickname.length === 0">{{ team.name }}</div>
28
<div v-else>{{ team.nickname }}</div>
29
</b-card-title>
30
<b-card-text>
31
{{ team.followers }} people like this team.
32
</b-card-text>
33
<b-button pill variant="danger" size="sm">delete</b-button>
34
35
</b-container>
36
<b-modal id="modal-1" :title="team.name">
37
<p class="my-4">{{team}}</p>
38
</b-modal>
39
</b-card>
40
</b-card-group>
41
</div>
42
</template>
43
and js
JavaScript
1
13
13
1
<script>
2
import { mapState } from 'vuex'
3
4
export default {
5
name: 'MyMyTeam',
6
computed: {
7
mapState({
8
myteams: 'myTeams'
9
})
10
},
11
12
}
13
i just wanna each card has its own modal
ex) when i click ManU
card, just one modal will be activated and it has ManU
data
but in my code, when i clicked a card, 3 modals was activated…. T1, ManU, Chelsea
how can i resole it?
Advertisement
Answer
Try to add ‘id’ in your Array, and put the ID of Array as a Key.
JavaScript
1
3
1
v-for="team in myteams"
2
:key="team.id"
3
Or, change the key of loop :key=”team.name” if you won’t add ‘id’