vue中v-for循环选中点击的元素并对该元素添加样式
html:<div v-for = "(item,index) in items":class = "active == index ? 'addclass' : '' " @click='dowm(index)'>{{item.name}}</div>css:css:.addclass{border-
·
html:
<div v-for = "(item,index) in items" :class = "active == index ? 'addclass' : '' " @click='dowm(index)'>
{{item.name}}
</div>
css:
css:
.addclass{
border-bottom: 3px solid #fb7299;
color: #fb7299;
}
js:
items :[
{
name :'点我1',
},
{
name:'点我2',
},
{
name:'点我3',
}
],
active : -1
}
dowm(index){
//将点击的元素的索引赋值给变量
this.active = index
}
更多推荐
已为社区贡献3条内容
所有评论(0)