更新记录

1.0.0(2025-08-19) 下载此版本

1.0.0 常用功能


平台兼容性

uni-app(4.07)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - - - - - - - -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - -

custom-headnav 组件说明

项目简介

  • 基于uni-app封装的自定义tabbar组件
  • 主要功能包括:自定义tabbar栏样式、tabbar数量、tabbar激活和未激活图片、tabbar标题、tabbar中间操作区图片和操作区事件等。
  • 兼容微信和支付宝小程序
  • 适配市场所有主流机型

注意事项

  • 使用此tabbar组件时,tabbar的页面切换数量(tabbarArr)必须为偶数,且必须在使用此组件的页面均定义。 示例:

    <general-tabbar :selectedTabBar="0" :isShowExtraOpera="true" :tabbarArr="tabbarArr"></general-tabbar>
    data() {
    return {
        tabbarArr: [
            {
                title: '首页',
                activateImg: '/static/images/tabbar_home_blue.png',
                inactiveImg: '/static/images/tabbar_home_gray.png',
                targetPage: '/pages/home/index'
            }, {
                title: '我的',
                activateImg: '/static/images/tabbar_my_blue.png',
                inactiveImg: '/static/images/tabbar_my_gray.png',
                targetPage: '/pages/personal/index'
            }
        ]
    }
    },
  • 使用此tabbar组件时,tabbarArr的格式要严格遵循示例(对象数组,每个对象内包含title、activateImg、inactiveImg和targetPage)。 示例:

    //tabbar内容(格式如下,需严格遵循)
    tabbarArr: {
        type: Array,
        default () {
            return [{
                title: '首页',
                activateImg: '/static/images/tabbar_home_blue.png',
                inactiveImg: '/static/images/tabbar_home_gray.png',
                targetPage: '/pages/home/index'
            }, {
                title: '我的',
                activateImg: '/static/images/tabbar_my_blue.png',
                inactiveImg: '/static/images/tabbar_my_gray.png',
                targetPage: '/pages/personal/index'
            }]
        }
    },
  • 使用此tabbar组件时,每个使用此组件的页面必须按tabbarArr内的下标定义当前页面的selectedTabBar(从0开始)。 示例:

     <!-- 首页 -->
     <general-tabbar :selectedTabBar="0" :isShowExtraOpera="true" :tabbarArr="tabbarArr"></general-tabbar>
    
     <!-- 我的 -->
     <general-tabbar :selectedTabBar="1" :isShowExtraOpera="true" :tabbarArr="tabbarArr"></general-tabbar>
    data() {
        return {
            tabbarArr: [
                {
                    title: '首页',
                    activateImg: '/static/images/tabbar_home_blue.png',
                    inactiveImg: '/static/images/tabbar_home_gray.png',
                    targetPage: '/pages/home/index'
                }, {
                    title: '我的',
                    activateImg: '/static/images/tabbar_my_blue.png',
                    inactiveImg: '/static/images/tabbar_my_gray.png',
                    targetPage: '/pages/personal/index'
                }
            ]
        }
    },
  • 使用自定义tabbar时,pages.json的tabBar.list需配置和tabbarArr内容同步的对象数据。 示例:

    "tabBar": {
        "custom": true,
        "color": "#000000",
        "selectedColor": "#3CC0FF",
        "backgroundColor": "#ffffff",
        "list": [{
                "iconPath": "/static/images/tabbar_home_gray.png",
                "selectedIconPath": "/static/images/tabbar_home_blue.png",
                "pagePath": "pages/home/index",
                "text": "首页"
            },
            {
                "iconPath": "/static/images/tabbar_my_gray.png",
                "selectedIconPath": "/static/images/tabbar_my_blue.png",
                "pagePath": "pages/personal/index",
                "text": "我的"
            }
        ]
    }

使用方式

  1. 修改pages.json文件(增加tabBar属性) 示例:

    "tabBar": {
        "custom": true,
        "color": "#000000",
        "selectedColor": "#3CC0FF",
        "backgroundColor": "#ffffff",
        "list": [{
                "iconPath": "/static/images/tabbar_home_gray.png",
                "selectedIconPath": "/static/images/tabbar_home_blue.png",
                "pagePath": "pages/home/index",
                "text": "首页"
            },
            {
                "iconPath": "/static/images/tabbar_my_gray.png",
                "selectedIconPath": "/static/images/tabbar_my_blue.png",
                "pagePath": "pages/personal/index",
                "text": "我的"
            }
        ]
    }
  2. 页面引入并定义tabbarArr后使用 示例:

    <general-tabbar :selectedTabBar="0" :isShowExtraOpera="true" :tabbarArr="tabbarArr"></general-tabbar>
    import generalTabbar from '@/components/general-tabbar.vue';
    export default {
        data() {
            return {
                tabbarArr: [
                    {
                        title: '首页',
                        activateImg: '/static/images/tabbar_home_blue.png',
                        inactiveImg: '/static/images/tabbar_home_gray.png',
                        targetPage: '/pages/home/index'
                    }, {
                        title: '我的',
                        activateImg: '/static/images/tabbar_my_blue.png',
                        inactiveImg: '/static/images/tabbar_my_gray.png',
                        targetPage: '/pages/personal/index'
                    }
                ]
            }
        },
        components: {
            generalTabbar
        },
    }

参数说明

Attributes
参数 状态 说明 类型 可选值 默认值
selectedTabBar 必传 当前选中的tabbar number 0
tabbarArr 必传 tabbar内容(格式如下,需严格遵循) object 详见上方注意事项中的第二点示例
tabbarHeight 非必传 tabbar的整体高度(单位:rpx) number 140
isShowExtraOpera 非必传 是否有中间的额外操作功能(此部分不作为页面展示,也无需在pages.json中配置) boolean false
imgWidth 非必传 tabbar图片的宽度(单位:rpx) number 50
imgHeight 非必传 tabbar图片的高度(单位:rpx) number 50
titleSize 非必传 tabbat标题的文字大小(单位:rpx) number 30
titleWeight 非必传 tabbat标题的文字字重 number 500
activateTitleColor 非必传 tabbar标题的激活颜色 string #3CC0FF
inactiveTitleColor 非必传 tabbar标题的未激活颜色 string #999999
extraOperaImg 非必传 中间额外操作区域的图片 string require('@/static/images/tabbar_sys_blue.png')
operaImgWidth 非必传 中间额外操作区域的图片宽度(单位:rpx) number 120
operaImgHeight 非必传 中间额外操作区域的图片高度(单位:rpx) number 120
方法
方法名 说明 注意点 参数
addOperation 中间额外操作功能区点击事件

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议