当前位置:网站首页>微信小程序中使用tabBar
微信小程序中使用tabBar
2022-07-02 01:17:00 【richest_qi】
前景知识
前面我们学习过:在app.json里对小程序进行全局配置,app.json的文件内容是一个JSON对象,包含很多属性,其中一个常用属性就是 tabBar。如果小程序是一个多tab应用,就可以通过tabBar指定tab栏的表现,以及tab切换时显示的对应页面。
tabBar 的属性值也是一个对象,该对象包含以下常用属性:
color,tab上文字的默认颜色,仅支持十六进制颜色,必填。selectedColor,tab上文字选中时的颜色,仅支持十六进制颜色,必填。backgroundColor,tab的背景颜色,仅支持十六进制颜色,必填。position,tabBar的位置,仅支持两个值:bottom和top,默认值是bottom。list,tab的列表,是一个数组,数组元素最少2个,最多5个。每个数组元素都是一个对象,包含以下属性值:pathPath,页面路径,必须在pages中定义,必填。text,tab上的文字,必填。iconPath,图片路径,非必填。icon大小限制为40kb,建议尺寸为81px*81px,不支持网络图片。当position值为top时,不显示icon。selectedIconPath,选中时的图片路径,非必填。icon大小限制为40kb,建议尺寸为81px*81px,不支持网络图片。当position为top时,不显示icon。
小程序项目
pages下新建Page:home(主页)、camera(拍照)、user(个人中心)。
- pages/home/
home.wxml、home.wxss、home.js、home.json - pages/camera/
camera.wxml、camera.wxss、camera.js、camera.json - pages/user/
user.wxml、user.wxss、user.js、user.json
项目根目录下新建文件夹:static,static下新建文件夹:images,images下新建文件夹:tabIcons,tabIcons下存放tabBar要用到的图标。
代码涉及的主要文件有:
- app.json
- pages/home/home.wxml
- pages/camera/camera.wxml
- pages/user/user.wxml

app.json
{
"pages": [
"pages/home/home",
"pages/camera/camera",
"pages/user/user"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white"
},
"tabBar": {
"color": "#000000",
"selectedColor": "#971a22",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/home/home",
"text": "主页",
"iconPath": "/static/images/tabIcons/home.png",
"selectedIconPath": "/static/images/tabIcons/home-fill.png"
},
{
"pagePath": "pages/camera/camera",
"text": "拍照",
"iconPath": "/static/images/tabIcons/camera.png",
"selectedIconPath": "/static/images/tabIcons/camera-fill.png"
},
{
"pagePath": "pages/user/user",
"text": "个人中心",
"iconPath": "/static/images/tabIcons/user.png",
"selectedIconPath": "/static/images/tabIcons/user-fill.png"
}
]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/home/home.wxml
<view class="camera">
Here is Home Page
</view>
pages/camera/camera.wxml
<view class="camera">
Here is Camera Page
</view>
pages/user/user.wxml
<view class="camera">
Here is User Page
</view>

相关链接
边栏推荐
- 站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
- 浅浅了解Servlet
- How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
- Global and Chinese market of aircraft MRO software 2022-2028: Research Report on technology, participants, trends, market size and share
- Daily work and study notes
- Global and Chinese market of ancillary software 2022-2028: Research Report on technology, participants, trends, market size and share
- 【八大排序①】插入排序(直接插入排序、希尔排序)
- No converter found for return value of type: class
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- GL Studio 5 安装与体验
猜你喜欢

The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!

With the acquisition of Xilinx, AMD is more than "walking on two legs" | Jiazi found

首场“移动云杯”空宣会,期待与开发者一起共创算网新世界!
![[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me](/img/b8/31a498c89cf96567640677e859df4e.jpg)
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me

PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)

【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码

GL Studio 5 安装与体验

How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
![[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card](/img/99/53b0ae47bada8b0d4db30d0517fe3d.jpg)
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card

Creating logical volumes and viewing and modifying attributes for AIX storage management
随机推荐
关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
Day 13 of hcip (relevant contents of BGP agreement)
MySQL winter vacation self-study 2022 12 (4)
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
Appium inspector can directly locate the WebView page. Does anyone know the principle
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
Recently, three articles in the nature sub Journal of protein and its omics knowledge map have solved the core problems of biology
BiLSTM-CRF代码实现
Learning note 24 - multi sensor post fusion technology
[WesternCTF2018]shrine writeup
工作中非常重要的测试策略,你大概没注意过吧
Docker installing Oracle_ 11g
cookie、session、tooken
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
Study note 2 -- definition and value of high-precision map
SAP ui5 beginner tutorial XXI - trial version of custom formatter of SAP ui5
cookie、session、tooken
6-2漏洞利用-ftp不可避免的问题
Mitsubishi PLC FX3U pulse axis jog function block (mc_jog)
S32Kxxx bootloader之UDS bootloader