微信小程序如何设置底部菜单栏(tab栏)

tabBar

如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。

属性说明
colortab 上的文字默认颜色
selectedColortab 上的文字选中时的颜色
backgroundColortab 的背景色
borderStyletabbar上边框的颜色, 仅支持 black / white 默认是bottom black
listtab 的列表,详见 list 属性说明,最少2个、最多5个 tab
positiontabBar的位置,仅支持 bottom / top  默认是bottom

其中 list 接受一个数组,只能配置最少2个、最多5个 tab。tab 按数组的顺序排序,每个项都是一个对象,其属性值如下:

属性说明
pagePath页面路径,必须在 pages 中先定义(也就是说必须要先有这一个页面)
texttab 上按钮文字
iconPath图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px。
当 postion 为 top 时,不显示 icon。
selectedIconPath选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px。
当 postion 为 top 时,不显示 icon。
{
  "pages": [
    "pages/index/index",
    "pages/logs/logs",
    "pages/movie/movie",
    "pages/userinfo/userinfo",
    "pages/navigateTo/navigateTo"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "我的小程序",
    "navigationBarTextStyle": "black",
    "navigationStyle": "default"
  },
  "tabBar": {
    "selectedColor": "green",
    "borderStyle": "white",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页",
        "iconPath": "images/index.png",
        "selectedIconPath": "images/indexf2.png"
      },
      {
        "pagePath": "pages/movie/movie",
        "text": "电影",
        "iconPath": "images/movie.png",
        "selectedIconPath": "images/movief.png"
      },
      {
        "pagePath": "pages/logs/logs",
        "text": "图片",
        "iconPath": "images/image.png",
        "selectedIconPath": "images/imagef.png"
      },
      {
        "pagePath": "pages/userinfo/userinfo",
        "text": "个人中心",
        "iconPath": "images/center.png",
        "selectedIconPath": "images/centerf.png"
      }
    ]
  }
}

微信公众平台的详细讲解地址:https://developers.weixin.qq.com/miniprogram/dev/framework/config.html

微信小程序中的底部菜单栏通常是通过`tabBar`配置项来实现的,它允许开发者在小程序中设置底部的导航,用于快速切换不同的页面。`tabBar`配置项中可以定义多个项,每个项可以指定其显示的文本、图标以及对应的页面路径。以下是设置底部菜单栏的基本步骤: 1. 在小程序的`app.json`全局配置文件中,找到或新增`tabBar`配置项。 2. 在`tabBar`对象中,至少需要设置`list`数组,这个数组包含了每个tab的配置信息,主要包括`pagePath`(页面路径)、`text`(显示的文本)和`iconPath`(未选中时的图标路径)、`selectedIconPath`(选中时的图标路径)。 3. 如果只需要一个底部菜单栏,可以定义一个`list`数组。如果有多个,还可以通过`color`、`selectedColor`、`backgroundColor`等属性来设置菜单栏的颜色样式。 4. 配置完毕后,微信小程序会根据这些设置自动生成底部菜单栏,并且在切换页面时,自动更新底部菜单栏的选中状态。 示例配置如下: ```json { "tabBar": { "color": "#8a8a8a", "selectedColor": "#333", "backgroundColor": "#ffffff", "position": "bottom", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "resources/home.png", "selectedIconPath": "resources/home_active.png" }, { "pagePath": "pages/logs/logs", "text": "日志", "iconPath": "resources/logs.png", "selectedIconPath": "resources/logs_active.png" } // 更多tab项... ] } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值