1、先在data裏面添加一個變量:isact,默認可設置爲0
data() {
isact: 0
}
2、在頁面中可以這麼寫:
<li v-for="(item, index) in shopSort" @click="tabsort(index)" :class="{ active: iscur == index }">{{ item }}</li>
3、在methods中添加一個方法:
tabsort(index) {
this.iscur = index;
}
2、針對一個div(點擊切換class)
<template>
<div>
<span :class="{'bg-primary text-danger':isA,'bg-success text-white':!isA}" @click="toggle()">AAAAA</span>
</div>
</template>
<script>
export default {
name: 'hello',
data () {
return {
isA: false
}
},
methods:{
toggle:function () {
this.isA = !this.isA
}
}
}
</script>
<style scoped>
/* todo */
</style>