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
}

Logo

前往低代码交流专区

更多推荐