更新记录

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

2025.8.8 v1.0.0 新增custom-headnav组件


平台兼容性

uni-app(4.07)

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

uni-app x(4.07)

Chrome Safari Android iOS 鸿蒙 微信小程序
- - - - - -

custom-headnav 组件说明

项目简介

  • 基于uni-app封装的自定义头部导航栏组件
  • 主要功能包括:自定义头部导航背景、自定义导航左侧图标及样式、自定义导航栏标题内容及样式和自定义导航栏排版布局
  • 兼容微信和支付宝小程序
  • 适配市场所有主流机型

注意点

  • 使用此组件的模块需定义hcSystemInfomations全局变量,用于获取当前系统信息。 示例:
    //全局变量
    data() {
            return {
                hcSystemInfomations: null, //系统信息
            }
        },
    //custom-headnav组件内的created已获取(const curSystemInfomations = getSystemInfo())并存入本地缓存
        mounted() {
            this.hcSystemInfomations = JSON.parse(uni.getStorageSync('hcSystemInfomations')) ? JSON.parse(uni.getStorageSync('hcSystemInfomations')) : {} //系统信息
        },
  • 为避免与内容区域排版冲突,使用此组件的模块在中需定义高度,此高度应与系统信息中的navHeight+statusBarHeight加额外的计算高度一致。 示例:
    <custom-headnav style="width: 100%;" :style="{height: headNavHeight}"></custom-headnav>
    computed: {
            //头部导航栏高度
            headNavHeight() {
                return this.hcSystemInfomations ?
                    `${this.hcSystemInfomations.navHeight + this.hcSystemInfomations.statusBarHeight + 10}rpx` : '176rpx'
            },
        },

使用方式

  1. 修改pages.json文件(目标模块的style配置,增加navigationStyle和usingComponents) 示例:

    "path": "pages/index/index",
    "style": {
      "navigationBarTitleText": "",
      "navigationStyle": "custom",
      "enablePullDownRefresh": false,
      "disableScroll": true,
      "mp-alipay": { //在支付宝小程序中如果不生效 就加上这两行代码 就会生效啦
        "transparentTitle": "always",
        "titlePenetrate": "YES"
      },
      "usingComponents": {
        "custom-headnav": "/components/custom-headnav"
      }
    }
  2. 模板模块引入并使用 示例:

    <custom-headnav style="width: 100%;" :style="{height: headNavHeight}"></custom-headnav>
    import customHeadnav from '@/components/custom-headnav.vue';
    export default {
      data() {
        return {
          hcSystemInfomations: null, //系统信息
        }
      },
      mounted() {
        this.hcSystemInfomations = JSON.parse(uni.getStorageSync('hcSystemInfomations')) ? JSON.parse(uni.getStorageSync('hcSystemInfomations')) : {} //系统信息
      },
      components: {
        customHeadnav
      },
      computed: {
        //头部导航栏高度
        headNavHeight() {
          return this.hcSystemInfomations ? `${this.hcSystemInfomations.navHeight + this.hcSystemInfomations.statusBarHeight + 10}rpx` : '176rpx'
        },
      },
      }

参数说明

Attributes
参数 状态 说明 类型 可选值 默认值
navbarBgImgUrl 非必传 头部导航栏背景图片 string require('@/static/images/nav_bg.png')
isShowOpera 非必传 是否需要操作按钮(左侧) boolean true
textContent 非必传 导航栏标题内容 string
fontSize 非必传 导航栏标题字体大小(单位:px) number 20
fontWeight 非必传 导航栏标题字体字重 number 600
fontColor 非必传 导航栏标题字体颜色 string '#ffffff'
textPaddingLeft 非必传 导航栏标题离左边的距离(单位:rpx) number 0
textAlign 非必传 导航栏标题的flex和text位置 left:左 center:中 string center
imgWidth 非必传 导航栏左侧操作区图片宽度(单位:rpx) number 60
imgHeight 非必传 导航栏左侧操作区图片高度(单位:rpx) number 60
operaImageUrl 非必传 导航栏左侧操作区图片 string require('@/static/images/nav_man.png')
方法
方法名 说明 注意点 参数
navOperaEvent 导航栏左侧操作区点击事件

隐私、权限声明

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

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

插件不采集任何数据

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

许可协议

MIT协议