微信小程序中使用colorui自定义tabbar按钮

废话不多说,直接上代码

app.json

{
  "pages": [

  ],
  "window": {
    "navigationBarBackgroundColor": "#379afb",
    "navigationBarTitleText": "青丰工具",
    "navigationStyle": "custom",
    "navigationBarTextStyle": "white"
  },
  "usingComponents": {},
  "tabBar": {
    "custom": true,
    "color": "#aaa",
    "selectedColor": "#39b54a",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [
      {
        "pagePath": "pages/information/information",
        "text": "找群"
      },
      {
        "pagePath": "pages/person/person",
        "text": "找人"
      },
      {
        "pagePath": "pages/release/release",
        "text": "发布"
      },
      {
        "pagePath": "pages/source/source",
        "text": "找资源"
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的"
      }
    ]
  },
  "sitemapLocation": "sitemap.json",
  "cloudfunctionRoot": "./cloudfunction/"

}

在这里插入图片描述
新建一个文件夹,名字叫custom-tab-bar

index.js

Component({
  properties: {

  },
  data: {
    selected:0,
    tabList:[
      {
        "pagePath": "pages/information/information",
        "text": "找群",
      },
      {
        "pagePath": "pages/person/person",
        "text": "找人",
      },
      {
        "pagePath": "pages/release/release",
        "text": "发布",
      },
      {
        "pagePath": "pages/source/source",
        "text": "找资源",
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的"
      }
    ]
  },
 
  methods: {
    switchTab(e){
       
      console.log(this.data)
      let key = Number(e.currentTarget.dataset.index);
      let tabList = this.data.tabList;
      let selected = key;
        this.setData({
          selected:key
        })
    
        wx.switchTab({
          url: `/${tabList[key].pagePath}`,
        })
     
    }
  }
})

index.wxml

<view class="box" >
	<view class="cu-bar tabbar">
		<view class="action {{selected === 0 ? 'text-green' : 'text-gray'}}" data-index="0" bindtap="switchTab">
      <view  class="{{selected === 0 ? 'icon-group_fill' : 'icon-group'}}"></view>找群

		</view>

		<view class="action {{selected === 1 ? 'text-green' : 'text-gray'}}" data-index="1" bindtap="switchTab">
      <view class="{{selected === 1 ? 'icon-friendaddfill' : 'icon-friendadd'}}"></view>找人
		</view>

		<view class="action {{selected === 2 ? 'text-green add-action' : 'text-gray add-action'}}"  data-index="2" bindtap="switchTab">
      <button class='cu-btn icon-add bg-gradual-blue shadow'></button>
      发布
		</view>

		<view class="action {{selected === 3 ? 'text-green' : 'text-gray'}}" data-index="3" bindtap="switchTab">
      <view class="{{selected === 3 ? 'icon-favorfill' : 'icon-favor'}}"></view>找资源
		</view>
	
		<view class="action {{selected === 4 ? 'text-green' : 'text-gray'}}" data-index="4" bindtap="switchTab">
      <view class="{{selected === 4 ? 'icon-myfill' : 'icon-my'}}">
        <!-- <view class='cu-tag badge'></view> -->
      </view>
      我的
		</view>

	</view>
</view>

index.wxss

@import "/colorui.wxss";
@import "/icon.wxss";

.tabbar{
  background-color: #ffffff;
 
}
.bg-cyan{
  background-color: #cce6ff;
}
.active{
  color: blue;
}
.default{
  color:rgb(51, 24, 24);
}


任意一个页面的方法中加入:

 tabBar(){
      if(typeof this.getTabBar === 'function' && this.getTabBar()){
       
        this.getTabBar().setData({
          selected:4,
        })
      }
    },

即可实现以下效果:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

青丰工具视频讲解

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风雷之霸主

感谢你的支持,我会持续输出

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值