微信小程序tab使用整理

一、微信小程序自带tab功能

目前在微信小程序中自带 多tab功能 ,使用简单,主要在配置文件中app.json添加配置.

tabBar

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

Tip:

  1. 当设置 position 为 top 时,将不会显示 icon
  2. tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。

属性说明:

属性类型必填默认值描述
colorHexColor tab 上的文字默认颜色
selectedColorHexColor tab 上的文字选中时的颜色
backgroundColorHexColor tab 的背景色
borderStyleStringblacktabbar上边框的颜色, 仅支持 black/white
listArray tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
positionStringbottom可选值 bottom、top

其中 list 接受一个数组,数组中的每个项都是一个对象,其属性值如下:

属性类型必填说明
pagePathString页面路径,必须在 pages 中先定义
textStringtab 上按钮文字
iconPathString图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPathString选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

 二、示例1,头部tab使用

tabBar配置如下:

"tabBar": {
    "color": "black",
    "selectedColor": "red",
    "backgroundColor": "orange",
    "position": "top",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页"
      },
      {
        "pagePath": "pages/movable/movable",
        "text": "移动测试"
      },
      {
        "pagePath": "pages/apptest/apptest",
        "text": "其他应用"
      }
    ]
  }

显示结果:

三、示例2,底部tab使用

tabBar配置如下:

 "tabBar": {
    "color": "gray",
    "selectedColor": "red",
    "backgroundColor": "orange",
    "list": [
      {
        "text": "首页",
        "pagePath": "pages/index/index",
        "iconPath": "style/img/home_gray.png",
        "selectedIconPath": "style/img/home_red.png"
      },
      {
        "text": "个人中心",
        "pagePath": "pages/apptest/apptest",
        "iconPath": "style/img/person_gray.png",
        "selectedIconPath": "style/img/person_red.png"
      },
      {
        "text": "推广名片",
        "pagePath": "pages/card/card",
        "iconPath": "style/img/card_gray.png",
        "selectedIconPath": "style/img/card_red.png"
      }
    ]
  }

显示结果:

 

更多:

微信小程序中打开其他小程序、小程序之间跳转

http://ad.jnqianle.cn/ad/11.html

http://www.jnqianle.cn/Mina/Index

转载于:https://my.oschina.net/tianma3798/blog/1789443

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值