I am working on a dynamic list of buttons that are populated using an array of objects:
<div
class="form-inline"
v-for="(genre, index) in genreArray"
:key="index"
>
<button class="btn m-1" type="button" @click="genreButton(genre, index)"
:class="[
{ 'clicked': clicked}
]"
>
{{ genre.name }}
</button>
</div>
The format of the array is as follows:
genreButton=[{
id='1234'
name='buttonOne'
},
//and many more objects with same key and different values
]
I am attempting to change the color of only the button that is clicked by adding a specific class to it:
data(){
return {
clicked: false
}
},
methods:{
genreButton(genre, index){
this.clicked = !this.clicked
}
}
Here is the CSS I am using for changing the color:
.clicked{
background-color= red;
}
However, I am facing an issue where all buttons change color when one is clicked. How can I ensure that ONLY the clicked button changes color?