微信小程序 — 自定义Tabbar

1.app.json

"tabBar": {
    "custom": true,
    "list": [
      {
        "pagePath": "pages/home/home",
        "text": "首 页"
      },
      ...//此处省略其他tabbar页面
    ]
}

重点 “custom”: true,其他按原生tabbar正常配置,每个tab页都要写不然无法跳转

2、app.json 文件夹新建目录

在这里插入图片描述
自定义tabbar
tabbar具体写法参考微信官方文档

3、每个Tabbar页面的js文件都要写

Component({
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          selected: 2
        })
      }
    }
  },
  methods: {
    onGotUserInfo: function (e) {
      console.log("nickname=" + e.detail.userInfo.nickName);
    }
  }
})

不写 —— 第一次点击页面跳转后没有点击态(点击3高亮的是0);页面的方法写在 Component(methods:{ })中,不能写在Page({ })中,不然找不到方法。

点击Tabbar 获取授权

在tabbar组件中添加button,不能使用for循环,不然每个tab都会弹出授权提示。

 <button open-type='getUserInfo' bindgetuserinfo="onGotUserInfo">
      <cover-image src="{{selected == index ? item.selectedIconPath : item.iconPath}}"></cover-image>
      <cover-view style="color: {{selected == index ? selectedColor : color}}">{{item.text}}</cover-view>
 </button>

tabbar 组件能直接使用tabbar页面的类

即:home页面所写类会影响tabbar显示,类的命名要注意。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值