vue自定义标签栏

由于elementUI不能满足需求,自己做一个自定义的标签栏

template部分

<div class="Tabchoice">
                    <div class="tabs">
                        <div :class="activeind==index?'plan-content':'plan-contents'" v-for="(item, index) in tabsArr"
                            :key="item.title" @click="saved(index)">
                            {{item.title}}
                            <i class="el-icon-close" v-if="activeind==index&&activeind!=0"
                                @click.stop="subtract(index)"></i>
                        </div>
                    </div>
                    <div class="addtab" @click="addtabs">
                        +
                    </div>
                </div>

data部分

tabsArr: [
                {
                    title: '道路1',
                    id: 0
                }
            ],
            activeind: 0,

methods部分

addtabs () {
            let num = this.tabsArr.length + 1;
            let nobj = {
                title: `道路${num}`,
            }
            this.tabsArr.push(nobj)
        },
        subtract (ind) {
            if (ind == 0) {
                return
            }
            this.tabsArr.splice(ind, 1)
            this.$nextTick(() => {
                this.activeind = 0
            })
        },
        saved (ind) {
            this.activeind = ind
        },

css部分

.Tabchoice {
    margin-left: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
}
.tabs {
    display: flex;
}
.plan-content {
    color: rgb(90, 166, 238);
    border-bottom: 2px solid rgb(90, 166, 238);
    padding: 10px 20px;
}
.plan-contents {
    color: black;
    border: none;
    padding: 10px 20px;
}
.addtab {
    font-size: 25px;
    cursor: pointer;
}

注:这样就可以做出一个自己的标签栏了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值