前端仿今日头条、网易新闻 tabs组件,根据文字多少自适应tab项宽度,支持自定义标题栏

发布时间 2023-05-26 21:26:28作者: 前端vue组件


快速实现 仿今日头条、网易新闻 tabs组件,根据文字多少自适应tab项宽度, 详情请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12560

代码如下:

# cc-tabs 说明 tabs组件,根据文字多少自适应tab项宽度,支持自定义标题栏

#### HTML代码部分

```html

<template>

<view class="content">

<!-- cc-tabs组件,根据文字自适应tab项宽度,支持自定义标题栏 -->

    <view style="margin-top:14px; margin-left: 8px; margin-right: 10px;">

<!-- spaceLeft设置tabs间距 -->

    <cc-tabs spaceLeft="14"  v-model="industryTabIndex" :tabs="industryTabs" @change="tabChange"></cc-tabs>

    </view>

</view>

</template>

```

#### JS代码 (引入组件 填充数据)

```javascript

<script>

import ccTabs from '@/components/cc-tabs.vue';

export default {

components: {

ccTabs

},

data() {

return {

title: 'Hello',

industryTabs: [{

name: '光伏产业'

},

{

name: '新能源车电池'

},

{

name: '银行金融'

},

{

name: '先进制造业'

},

{

name: '医疗健康'

},

{

name: '食品饮料白酒'

},

{

name: '行业七'

},

{

name: '行业八'

}

],

industryTabIndex: 0,

}

},

onLoad() {

},

methods: {

tabChange() {

console.log('切换行业类型 =' + this.industryTabIndex);

},

}

}

</script>

```

#### CSS

```CSS

<style>

page{

 

}

.content {

display: flex;

flex-direction: column;

}

</style>

```

效果图如下: