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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunshineBlog/article/details/83004015

tabBar

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

属性 说明
color tab 上的文字默认颜色
selectedColor tab 上的文字选中时的颜色
backgroundColor tab 的背景色
borderStyle tabbar上边框的颜色, 仅支持 black / white 默认是bottom black
list tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
position tabBar的位置,仅支持 bottom / top  默认是bottom

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

属性 说明
pagePath 页面路径,必须在 pages 中先定义(也就是说必须要先有这一个页面)
text tab 上按钮文字
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

猜你喜欢

转载自blog.csdn.net/SunshineBlog/article/details/83004015