I have a Vue component, which displays a Vote button. When the user clicks on the Vote button an .active class gets added. Now I need to make sure only one Vote button can have this .active class at any given time.
What do I need to change in my code:
Vue.component('moustache', {
name: 'moustache',
props: ['type', 'img'],
template: `<li>
<p><strong>@{{ type }}</strong></p>
<img width="300" height="200" :src="img">
<button class="btn btn-primary" v-bind:class="{ active: isActive }" :data-type="type" @click="toggleClass">
Vote
</button>
</li>`,
data: function(){
return{
isActive: false
}
},
methods: {
toggleClass(){
this.isActive = !this.isActive;
}
}
});
new Vue({
el: '#app'
});