HTML代码
<div class="change">
<li
:class="{ active: activeIndex === item }"
v-for="item in monthList"
:key="item"
@click="activeIndex = item"
:style="myStyle"
>
{{ item }}个月
</li>
</div>
JS代码
data() {
return {
activeIndex: 1,
}
},
computed: {
myStyle() {
switch (this.activeIndex) {
case 1:
return {
'--radius': '6px 0 0 6px',
}
case 12:
return {
'--radius': '0 6px 6px 0',
}
default:
return {
'--radius': '0 0 0 0',
}
}
},
},
LESS代码
.active {
background: #30b27a;
color: var(--unnamed, #fff);
border-radius: var(--radius);
}