html" title=vue>vue_0">html" title=vue>vue点击变色
<div v-for="(item,index) in showList" v-show="index<num" :id="index" :key="index" :class="{blue:text===index}" class="hi" style=" float:left; width:auto;text-align:center;margin-left: 15px; margin-right:25px;cursor:pointer;" @click="singleItemList(item.id),changSemester(index)">
<img :src="item.logo" alt="" style="width:22px;height:22px;float:left">
<p style="float:left;margin-top:4px;margin-left:10px;">{{ item.name }}</p>
</div>
在data里面定义text默认选中颜色,不想默认选中改为-1即可
data() {
return {
text:1,
}
}
在css中定义颜色
.blue {
color: blue;
}