动态绑定class名
<template>
<view class='tab'>
<view class='item' :class='{active: index == 1}' @click='handleChange(1)'>热门</view>
<view class='item' :class='{active: index == 2}' @click='handleChange(2)'>附近</view>
<view class='item' :class='{active: index == 3}' @click='handleChange(3)'>热门</view>
</view>
</template>
<script>
export default {
data() {
return {
index: 1
}
},
methods: {
handleChange(index) {
this.index = index;
}
}
}
</script>
<style>
.tab {
xxx: xxx;
}
.tab .item {
xxx: xxx;
}
.tab .item.active {
xxx:xxx
}
</style>
点击的时候改变他的样式不就ok了