前端Vue自定义可自由滚动精美tabs选项卡标签栏标题栏 可设置背景颜色,

随着技术的发展,开发的复杂度也越来越高,传统开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。通过组件化开发,可以有效实现单独开发,单独维护,而且他们之间可以随意的进行组合。大大提升开发效率低,降低维护成本。

组件化对于任何一个业务场景复杂的前端应用以及经过多次迭代之后的产品来说都是必经之路。组件化要做的不仅仅是表面上看到的模块拆分解耦,其背后还有很多工作来支撑组件化的进行,例如结合业务特性的模块拆分策略、模块间的交互方式和构建系统等等 。

本文给大家介绍的一款组件是:

前端Vue自定义可自由滚动精美tabs选项卡标签栏标题栏 可设置背景颜色, 

效果图如下:

format,png

format,png

format,png

format,png

# cc-scrollTag

#### 使用方法

```使用方法

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagList" bgColor="#FA436A"></cc-scrollTag>

```

#### HTML代码实现部分

```html

<template>

<view class="content">

<view style="height: 22px;margin: 12px 20px;">红色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagList" bgColor="#FA436A"></cc-scrollTag>

<view style="height: 22px;margin: 12px 20px;">橙色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagListTwo" bgColor="#f37b1d"></cc-scrollTag>

<view style="height: 22px;margin: 12px 20px;">粉色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagList" bgColor="#e03997"></cc-scrollTag>

<view style="height: 22px;margin: 12px 20px;">绿色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagListTwo" bgColor="#39b54a"></cc-scrollTag>

<view style="height: 22px;margin: 12px 20px;">黄色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagList" bgColor="#fbbd08"></cc-scrollTag>

<view style="height: 22px;margin: 12px 20px;">橄榄色背景滑动标签栏</view>

<!-- tabChange: tab选择事件 tagList:tab数据 bgColor:标签背景颜色-->

<cc-scrollTag @tabChange="tabChange" :tagsList="tagListTwo" bgColor="#8dc63f"></cc-scrollTag>

</view>

</template>

<script>

export default {

data() {

return {

tagList: [

'首页', '标题一', '标题二', '标题三', '标题四',

'标题五', '标题六',

'标题七', '标题八'

],

tagListTwo: [

'推荐',

'选项一',

'选项二',

'选项三',

'选项四',

'选项五',

'选项六',

'选项七',

'选项八',

],

}

},

onLoad() {

},

methods: {

tabChange: function(t) {

console.log("tab选择序列 = " + JSON.stringify(t));

},

}

}

</script>

<style>

.content {

display: flex;

flex-direction: column;

}

</style>

```

阅读全文下载完整组件代码请关注微信公众号: 前端组件开发

d848d5658a07453c843277846948c608.png

  欢迎加入我们的前端组件学习交流群,可添加群主微信,审核通过后入群。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Ant Design Vue 中的 Tabs 组件可以与 Vue Router 配合使用,实现标签的功能。具体步骤如下: 1. 在路由配置中,添加 `meta` 字段用于标识当前路由是否需要在标签中显示,例如: ```javascript const routes = [ { path: '/', name: 'Home', component: Home, meta: { title: '首页', keepAlive: true, // 是否缓存组件 showTab: true, // 是否在标签中显示 }, }, // ... ]; ``` 2. 在 App.vue 中,使用 Tabs 组件来渲染标签,并使用 `router-view` 组件来渲染当前路由对应的组件: ```html <template> <div> <a-tabs v-model:selectedTabKey="selectedTabKey" type="editable-card" hide-add @edit="handleTabEdit" style="margin: 0 24px;"> <a-tab-pane v-for="(tab, index) in tabs" :key="tab.key" :tab="tab.title" :closable="index !== 0" @close="handleTabClose(index)"> </a-tab-pane> </a-tabs> <router-view /> </div> </template> <script> export default { data() { return { selectedTabKey: '/', tabs: [ { key: '/', title: '首页', }, ], }; }, created() { const { path, meta } = this.$route; if (meta.showTab) { this.selectedTabKey = path; this.addTab(path, meta.title); } }, methods: { addTab(key, title) { const index = this.tabs.findIndex((tab) => tab.key === key); if (index === -1) { this.tabs.push({ key, title, }); } }, removeTab(key) { const index = this.tabs.findIndex((tab) => tab.key === key); if (index !== -1) { this.tabs.splice(index, 1); } }, handleTabClose(index) { const { key } = this.tabs[index]; this.removeTab(key); this.$router.replace(this.tabs[this.tabs.length - 1].key); }, handleTabEdit(targetKey, action) { if (action === 'add') { this.$router.push(targetKey); } else if (action === 'remove') { this.handleTabClose(this.tabs.findIndex((tab) => tab.key === targetKey)); } }, }, }; </script> ``` 在这个示例中,我们使用了 `selectedTabKey` 属性来绑定当前选中的标签页,使用 `tabs` 数组来存储所有已打开的标签页。在 `created` 钩子函数中,我们通过判断当前路由的 `meta.showTab` 字段来决定是否需要添加标签页。在 `addTab` 方法中,我们使用 `tabs` 数组来存储已打开的标签页,防止重复添加。在 `removeTab` 方法中,我们使用 `tabs` 数组来删除已关闭的标签页。在 `handleTabEdit` 方法中,我们通过判断用户的操作来决定是添加标签页还是关闭标签页。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端组件开发

你的钟意将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值