《微信小程序》第七章:TabBar设计

系列文章

《微信小程序》https://blog.csdn.net/sen_shan/category_13069009.html

第六章:参数定义与管理https://blog.csdn.net/sen_shan/article/details/153965573

文章目录

目录

系列文章

文章目录

前言

图标下载

[修改 pages.json](#修改 pages.json)

一、概述

二、配置位置

三、字段详解

[四、list 节点说明](#四、list 节点说明)

五、完整代码

六、开发与调试注意事项

七、常见报错速查

演示效果


前言

本文介绍了uni-app开发微信小程序时如何配置底部导航栏(tabBar)。

主要内容包括:

1)在阿里图标库下载图标并保存到指定目录;

2)修改pages.json文件配置tabBar相关参数,包括颜色、选中样式和各tab页的路径、文字、图标;

3)详细解释了tabBar各项配置字段的含义和使用规范;

4)提供了完整的配置代码示例;

5)总结了开发调试中的7个注意事项,如路径大小写敏感、页面必须提前注册、H5与小程序的差异等;

6)最后给出了效果演示和官方文档参考链接。文章旨在帮助开发者快速掌握微信小程序底部导航栏的配置方法。

图标下载

设计图标与活动图标,然后下载到static/icon/tabBar

阿里图标库https://www.iconfont.cn

修改 pages.json

修改 pages.json 文件

复制代码
"tabBar": {
	    "color": "#7A7E83",
	    "selectedColor": "#07c160",
	    "list": [
	      { "pagePath": "pages/index/index", 
		  "text": "首页",
		   "iconPath": "static/icon/tabBar/home.png",
		   "selectedIconPath": "static/icon/tabBar/home-active.png" },
	      { "pagePath": "pages/category/index", 
		   "text": "分类",
		   "iconPath": "static/icon/tabBar/category.png",
		   "selectedIconPath": "static/icon/tabBar/category-active.png" },
	      { "pagePath": "pages/cart/index", 
		   "text": "购物车",
		   "iconPath": "static/icon/tabBar/cart.png",
		   "selectedIconPath": "static/icon/tabBar/cart-active.png" },
	      { "pagePath": "pages/mine/index", 
		  "text": "我的" ,
		   "iconPath": "static/icon/tabBar/mine.png",
		   "selectedIconPath": "static/icon/tabBar/mine-active.png"
		  }
	    ]
	  },

一、概述

基于 uni-app 框架开发的 微信小程序 项目在 pages.json 中配置的底部导航栏(tabBar)字段含义、资源规范及常见注意事项,方便前后端、UI、测试快速查阅。

二、配置位置

pages.json 位于项目根目录,是 uni-app 全局路由与窗口表现配置文件。

tabBar 节点与 "pages" 、 "globalStyle" 同级。

复制代码
{
  "pages": [ ... ],
  "globalStyle": { ... },
  "tabBar": { ... }   // ← 本文档说明对象
}

三、字段详解

四、list 节点说明

每一项对应一个底部标签页,字段如下:

五、完整代码

bash 复制代码
{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path" : "pages/login/index",
			"style" : 
			{
				"navigationBarTitleText" : "登录"
			}
		},
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "首页"
			}
		},
		{
			"path" : "pages/cart/index",
			"style" : 
			{
				"navigationBarTitleText" : "购物车"
			}
		},
		{
			"path" : "pages/category/index",
			"style" : 
			{
				"navigationBarTitleText" : "分类"
			}
		},

		{
			"path" : "pages/mine/index",
			"style" : 
			{
				"navigationBarTitleText" : "我的"
			}
		}
	],
	// "tabBar": {"custom": true },
	 "tabBar": {
	    "color": "#7A7E83",
	    "selectedColor": "#07c160",
	    "list": [
	      { "pagePath": "pages/index/index", 
		  "text": "首页",
/* 		    "iconfont": {
		      "text": "\ue602",          //首页图标 unicode 
		      "selectedText": "\uf6eb",
		      "fontSize": "24px",
		      "color": "#7A7E83",
		      "selectedColor": "#07c160"
		    } */
		   "iconPath": "static/icon/tabBar/home.png",
		   "selectedIconPath": "static/icon/tabBar/home-active.png" 
		  },
	      { "pagePath": "pages/category/index", 
		   "text": "分类",
		   "iconPath": "static/icon/tabBar/category.png",
		   "selectedIconPath": "static/icon/tabBar/category-active.png" },
	      { "pagePath": "pages/cart/index", 
		   "text": "购物车",
		   "iconPath": "static/icon/tabBar/cart.png",
		   "selectedIconPath": "static/icon/tabBar/cart-active.png" },
	      { "pagePath": "pages/mine/index", 
		  "text": "我的" ,
		   "iconPath": "static/icon/tabBar/mine.png",
		   "selectedIconPath": "static/icon/tabBar/mine-active.png"
		  }
	    ]
	  }, 
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	},
	"uniIdRouter": {}
}

六、开发与调试注意事项

  1. 路径大小写敏感

微信小程序真机区分大小写,确保 pages.json 中的 pagePath 与目录完全一致。

  1. 页面必须提前注册

所有 pagePath 必须在 "pages" 数组里先声明,否则编译失败。

  1. H5 与小程序差异

H5 端 tabBar 由 uni-app 模拟,自定义性更高;小程序端完全受微信客户端约束,不支持动态隐藏某一项。

  1. 红点/数字角标

需通过 uni.setTabBarBadge / uni.removeTabBarBadge 在业务逻辑中控制,与配置无关。

  1. 图标颜色

微信会取图标 有像素区域 做纯色填充,因此设计稿务必使用 纯灰度图标,否则会出现色差。

  1. 审核经验

文字需与页面功能强相关,避免"未实现功能"被拒。

7.图标规范

图标 8 张(4 功能 ×2 状态)已压缩 ≤40 KB

图标命名规范: *-active.png 为选中态

七、常见报错速查

八、参考资料
uni-app 官方路由配置https://uniapp.dcloud.net.cn/collocation/pages.html#tabbar

微信小程序 tabBar 设计指南https://developers.weixin.qq.com/miniprogram/design/

演示效果

相关推荐
程序0074 小时前
微信小程序app.js错误:require is not defined
javascript·微信小程序·小程序
云起SAAS4 小时前
斗兽棋象狮虎豹狼小游戏抖音快手微信小程序看广告流量主开源
微信小程序·小程序·ai编程·看广告变现轻·斗兽棋象狮虎豹狼小游戏
幽络源小助理4 小时前
微信小程序火锅店点餐系统SSM源码
微信小程序
说私域5 小时前
基于“开源AI智能名片链动2+1模式S2B2C商城小程序”的会员制培养策略研究
人工智能·小程序
2501_915921435 小时前
iOS 26 描述文件管理与开发环境配置 多工具协作的实战指南
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915909065 小时前
iOS 抓包实战 从原理到复现、定位与真机取证全流程
android·ios·小程序·https·uni-app·iphone·webview
江城开朗的豌豆5 小时前
webpack了解吗,讲一讲原理,怎么压缩代码
前端·javascript·微信小程序
江城开朗的豌豆5 小时前
Webpack配置魔法书:从入门到高手的通关秘籍
前端·javascript·微信小程序
江城开朗的豌豆5 小时前
玩转小程序生命周期:从入门到上瘾
前端·javascript·微信小程序