How to toggle active class, i.e. if i clicked on the element, an active class should be added to this item and removed from another.
<th @click="sort('campaign')" class="initial" :class="{active: isActive}">Campaign</th> // here i am toggling class
<th @click="sort('time')" class="initial" :class="{active: isActive}">Time</th>
<th @click="sort('views')" class="initial" :class="{active: isActive}">Views</th>
<th @click="sort('visitors')" class="initial" :class="{active: isActive}">Visitors</th>
<th @click="sort('ctr')" class="initial" :class="{active: isActive}">CTR</th>
<th @click="sort('cpc')" class="initial" :class="{active: isActive}">CPC</th>
<th @click="sort('cpv')" class="initial" :class="{active: isActive}">CPV</th>
<th @click="sort('cpm')" class="initial" :class="{active: isActive}">CPM</th>
<th @click="sort('status')" class="initial" :class="{active: isActive}">Status</th>
data(){
return{
isActive: false
}
}
sort(s) {
//if s == current sort, reverse
this.isActive = !this.isActive;
if(s === this.currentSort) {
this.currentSortDir = this.currentSortDir==='asc'?'desc':'asc';}
this.currentSort = s;
}
When i am clicking, class toggles on all items. Maybe i should make a component so that it has a local state.