美文网首页微信小程序
自定义 tabBar的两种方式

自定义 tabBar的两种方式

作者: wsgdiv | 来源:发表于2021-02-01 20:53 被阅读0次

一、官方文档中的方法

内容如下:

使用流程

1. 配置信息

  • app.json 中的 tabBar 项指定 custom 字段,同时其余 tabBar 相关配置也补充完整。
  • 所有 tab 页的 json 里需声明 usingComponents 项,也可以在 app.json 全局开启。

示例:

{
  "tabBar": {
    "custom": true,
    "color": "#000000",
    "selectedColor": "#000000",
    "backgroundColor": "#000000",
    "list": [{
      "pagePath": "page/component/index",
      "text": "组件"
    }, {
      "pagePath": "page/API/index",
      "text": "接口"
    }]
  },
  "usingComponents": {}
}

2. 添加 tabBar 代码文件

在代码根目录下添加入口文件:

custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.wxml
custom-tab-bar/index.wxss

3. 编写 tabBar 代码

用自定义组件的方式编写即可,该自定义组件完全接管 tabBar 的渲染。另外,自定义组件新增 getTabBar 接口,可获取当前页面下的自定义 tabBar 组件实例

二、直接创建pages/index/index,在index.html中设置wx:if判断做为转换底部tabBar的条件,联合index.js中的按钮赋值,就可以了。

相关文章

网友评论

    本文标题:自定义 tabBar的两种方式

    本文链接:https://www.haomeiwen.com/subject/ripstltx.html