微信小程序自定义底部导航栏,切换不同页面显示不同tabbar

在一个微信小程序中想要用到两种不同的tabbar样式,需要在app.js中自定义,在页面加载时进行调用。
在这里插入图片描述
第一个tabbar
首先有一个模板文件:tabbar.wxml

<template name="tabBar">    
  <view class="tab-bar" style="color: {
  
  {tabBar.color}}; background: {
  
  {tabBar.backgroundColor}}; {
  
  {tabBar.position=='top'? 'top: 0' : 'bottom: 0'}};">    
  <block wx:for="{
  
  {tabBar.list}}" wx:key="pagePath">    
    <navigator hover-class="none" url="{
  
  {item.pagePath}}" open-type="redirect" class="{
  
  {item.clas}}" style="{
  
  {item.active? 'color: '+(item.selectedColor? item.selectedColor : tabBar.selectedColor) : ''}}">    
      <image src="{
  
  {item.selectedIconPath}}" wx:if="{
  
  {item.active}}" class="img"></image>    
      <image src="{
  
  {item.iconPath}}" wx:if="{
  
  {!item.active}}" class="img"></image>  
      <text class="tabbar_text">{
  
  {item.text}}</text>    
    </navigator>    
    </block>  
    <view class="clear"></view>    
  </view>    
</template> 

在app.js中自定义如下
这里我的cbl是封装好的请求

const cbl = require('utils/cbl.js');
var usercode=""
App({
  onLaunch: function () {

    var that=this;
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        if(res.data){
          usercode = res.data.UserCode;
        }else{
          usercode = ""
        }
      }
    })
  },
  //第一种底部  
  editTabBar: function () {
 
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值