likes
comments
collection
share

前端vue自适应文字宽度下划线tabs可设置下划线颜色(更新版)

作者站长头像
站长
· 阅读数 9

前端vue自适应文字宽度下划线tabs可设置下划线颜色, 下载完整代码请访问uni-app插件市场地址: ext.dcloud.net.cn/plugin?id=1…

效果图如下:

前端vue自适应文字宽度下划线tabs可设置下划线颜色(更新版)

前端vue自适应文字宽度下划线tabs可设置下划线颜色(更新版)

实现代码如下:

使用方法


<!-- tabIndex:选择序列 tabs:选择数组 myColor:下划线颜色 spaceLeft:tabs间距 height:设置高度 @change:tabs切换事件 -->
<cc-underLineTabs :tabIndex="tabIndex" :tabs="tabs" @change="tabChange"></cc-underLineTabs>

HTML代码部分


<template>
    <view class="content">
        <view style="margin: 10px;">默认设置</view>

        <!-- tabIndex:选择序列 tabs:选择数组 myColor:下划线颜色 spaceLeft:tabs间距 height:设置高度 @change:tabs切换事件 -->
        <cc-underLineTabs :tabIndex="tabIndex" :tabs="tabs" @change="tabChange"></cc-underLineTabs>

        <view style="margin: 10px;color: #88888;">设置下划线颜色</view>
        <cc-underLineTabs :tabIndex="tabIndexTwo" myColor="red" :tabs="tabs" @change="tabChangeTwo"></cc-underLineTabs>

        <view style="margin: 10px;color: #88888;">设置间距</view>
        <cc-underLineTabs :tabIndex="tabIndexThree" spaceLeft="20" :tabs="tabs"
            @change="tabChangeThree"></cc-underLineTabs>

        <view style="margin: 10px;color: #88888;">设置行高</view>
        <cc-underLineTabs :tabIndex="tabIndexfour" myColor="red" height="90" :tabs="tabs"
            @change="tabChangeFour"></cc-underLineTabs>

        <view style="height: 300px;background-color: antiquewhite;"></view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                tabIndex: 0,
                tabs: ['资讯', '体育', '视频', '直播', '凤凰卫视', '政务', '美好中国', '财经', '娱乐', '时尚', '汽车', '房产'],

                tabIndexTwo: 0,
                tabIndexThree: 0,
                tabIndexfour: 0
            }
        },

        methods: {
            tabChange(e) {
                console.log("切换tag = " + JSON.stringify(e));
                this.tabIndex = e;
            },
            tabChangeTwo(e) {
                console.log("切换tag = " + JSON.stringify(e));
                this.tabIndexTwo = e;
            },
            tabChangeThree(e) {
                console.log("切换tag = " + JSON.stringify(e));
                this.tabIndexThree = e;
            },
            tabChangeFour(e) {
                console.log("切换tag = " + JSON.stringify(e));
                this.tabIndexfour = e;
            }
        }
    }
</script>

<style>
    .content {
        display: flex;
        flex-direction: column;
    }

    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 200rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }

    .text-area {
        display: flex;
        justify-content: center;
    }

    .title {
        font-size: 36rpx;
        color: #8f8f94;
    }
</style>