Vue点击选中(多选)选中右下角有三角形?怎么实现这种选中效果?

作者站长头像
站长
· 阅读数 15
 <div class="tag">
                <span class="Classification"
                v-for="(item, index) in tags"
                :class="{active : tabIndex.includes(item) }"
                @click="oncheck(item)">
                    {{item.name}}
                </span>
            </div>
        </template>


oncheck(item) {
            console.log('111111111111', item)
            if (this.tabIndex.includes(item)) {
                this.tabIndex = this.tabIndex.filter(function(ele) {
                    return ele != item
                })
            } else {
                this.tabIndex.push(item)
            }
            console.log('33333333333333', this.tabIndex)

        },



.tag{
    display: inline-block;
    height: auto;
    line-height: 35px;
    cursor: pointer;
    .Classification{
        padding: 6px;
        background: #FFFFFF;
        font-size: 12px;
        font-weight: 400;
        color: #A8AAAF;
        border: 1px solid #D2D5D6;
        margin-right: 8px;
    }
    .active{
        height: 14px;
        margin-right: 8px;
        padding: 6px;
        color: #67C23A;
        border: 1px solid #67C23A;
    }
    .active:before {
        content: '';
        position: absolute;
        right: 0;
        bottom: 0;
        border: 10px solid #67C23A;
        border-top-color: transparent;
        border-left-color: transparent;
    }
    .active:after {
        content: '';
        width: 4px;
        height: 6px;
        position: absolute;
        right: 4px;
        bottom: 3px;
        border: 2px solid #fff;
        border-top-color: transparent;
        border-left-color: transparent;
        transform: rotate(45deg);
    }
}

Vue点击选中(多选)选中右下角有三角形?怎么实现这种选中效果?Vue点击选中(多选)选中右下角有三角形?怎么实现这种选中效果?Vue点击选中(多选)选中右下角有三角形?怎么实现这种选中效果?

回复
1个回答
avatar
test
2024-07-17

<div class="tag">

<span class="Classification"
v-for="(item, index) in tags"
:class="{active : tabIndex.includes(item) }"
@click="oncheck(item)">
    {{item.name}}
</span>

</div>

在这里插入代码片
 oncheck(item) {
   if (this.tabIndex.includes(item)) { 
       this.tabIndex = this.tabIndex.filter(function(ele) {
           return ele != item
       })
   } else {
       this.tabIndex.push(item)
   }
},

.tag{

display: inline-block;
height: auto;
line-height: 35px;
cursor: pointer;
.Classification{
    padding: 6px;
    background: #FFFFFF;
    font-size: 12px;
    font-weight: 400;
    color: #A8AAAF;
    border: 1px solid #D2D5D6;
    margin-right: 8px;
}
.active{
    position: relative;
    height: 14px;
    margin-right: 8px;
    padding: 6px;
    color: #67C23A;
    border: 1px solid #67C23A;
}
.active::before {
    content: '';
    position: absolute;
    right: -1px;
    bottom: 0;
    border: 8px solid #67C23A;
    border-top-color: transparent;
    border-left-color: transparent;
}
.active::after {
    content: '';
    width: 2px;
    height: 5px;
    position: absolute;
    right: 2px;
    bottom: 2px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-left-color: transparent;
    transform: rotate(45deg);
}

}

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容