做这个 遇到问题比较多,特此记录以便查看,直接上代码:

一、app.js

控制原有菜单隐藏、启用新菜单、菜单列表,集中在这里控制

hideTabBar这个很关键,解决苹果6S导致的双导航栏:原文https://blog.csdn.net/czp555/article/details/87258301

hideTabBar: function () {
wx.hideTabBar({
fail: function () {
setTimeout(function () {
wx.hideTabBar()
}, 500)
}
});
},
editTabbar: function() {
let tabbar = this.globalData.tabBar;
let currentPages = getCurrentPages();
let _this = currentPages[currentPages.length - 1];
let pagePath = _this.route;
(pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
for (let i in tabbar.list) {
tabbar.list[i].selected = false;
(tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
}
_this.setData({
tabbar: tabbar
});
},
globalData: {
tabBar: {
"color": "#f3f3f3",
"selectedColor": "#f3f3f3",
"borderStyle": "white",
"backgroundColor": "#ff731d",
"list": [{
"pagePath": "/youfan_market/pages/index/index",
"text": "首页",
"iconPath": "/youfan_market/resource/images/tabBar/home.png",
"selectedIconPath": "/youfan_market/resource/images/tabBar/home.png"
},
{
"pagePath": "/youfan_market/pages/category/category",
"text": "分类",
"iconPath": "/youfan_market/resource/images/tabBar/category.png",
"selectedIconPath": "/youfan_market/resource/images/tabBar/category.png"
},
{
"pagePath": "/youfan_market/pages/user/index",
"text": "分享转发",
"iconPath": "/youfan_market/resource/images/tabBar/share.png",
"selectedIconPath": "/youfan_market/resource/images/tabBar/share.png",
isShare: true
},
{
"pagePath": "/youfan_market/pages/cart/cart",
"text": "购物车",
"iconPath": "/youfan_market/resource/images/tabBar/cart.png",
"selectedIconPath": "/youfan_market/resource/images/tabBar/cart.png"
},
{
"pagePath": "/youfan_market/pages/user/index",
"text": "我的",
"iconPath": "/youfan_market/resource/images/tabBar/user.png",
"selectedIconPath": "/youfan_market/resource/images/tabBar/user.png"
}
]
}
},

二、自定义组件

关于图标资源就不发了,需要的自己去iconfont找

在小程序根目录创建组件文件夹 tabbarComponent

tabbar.js

// tabBarComponent/tabBar.js
const app = getApp();
Component({
/**
* 组件的属性列表
*/
properties: {
tabbar: {
type: Object,
value: {
"backgroundColor": "#ffffff",
"color": "#979795",
"selectedColor": "#1c1c1b",
"list": []
}
}
},
/**
* 组件的初始数据
*/
data: {
isIphoneX:false // app.globalData.systemInfo.model == "iPhone X" ? true : false,
}, /**
* 组件的方法列表
*/
methods: {
},
})

tabbar.json

{
"component": true,
"usingComponents": {}
}

tabbar.wxml

<view class="tabbar_box {{isIphoneX?'iphoneX-height':''}}" style="background-color:{{tabbar.backgroundColor}}">
<block wx:for="{{tabbar.list}}" wx:key="{{item.pagePath}}">
<navigator wx:if="{{item.isSpecial}}" class="tabbar_nav" hover-class="none" url="{{item.pagePath}}" style="color:{{tabbar.selectedColor}}" open-type="navigate">
<view class='special-wrapper'><image class="tabbar_icon" src="{{item.iconPath}}"></image></view>
<image class='special-text-wrapper'></image>
{{item.text}}
</navigator>
<button wx:elif='{{item.isShare}}' class="tabbar_nav tabbar_btn" hover-class="none" style="color:{{tabbar.color}};border-radius:90%;" open-type="share">
<image class="tabbar_icon" src="{{item.iconPath}}"></image>
{{item.text}}
</button>
<!-- <navigator wx:else class="tabbar_nav" hover-class="none" url="{{item.pagePath}}" style="color:{{item.selected ? tabbar.selectedColor : tabbar.color}}" open-type="redirect">
<image class="tabbar_icon" src="{{item.selected ? item.selectedIconPath : item.iconPath}}"></image>
<text>{{item.text}}</text>
</navigator> -->
<navigator wx:else class="tabbar_nav" hover-class="none" url="{{item.pagePath}}" style="color:{{item.selected ? tabbar.selectedColor : tabbar.color}}" open-type="switchTab">
<image class="tabbar_icon" src="{{item.selected ? item.selectedIconPath : item.iconPath}}"></image>
{{item.text}}
</navigator>
</block>
</view>

tabbar.wxss

.tabbar_box {
display: flex;
flex-direction: row;
justify-content: space-around;
position: fixed;
bottom: 0;
left: 0;
z-index: 999999;
width: 100%;
height: 98rpx;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
} .tabbar_box.iphoneX-height {
padding-bottom: 66rpx;
} .middle-wrapper {
position: absolute;
right: 310rpx;
bottom: 0;
background-color: #fff;
width: 120rpx;
height: 120rpx;
border-radius: 50%;
border-top: 2rpx solid #f2f2f3;
} .middle-wrapper.iphoneX-height {
bottom: 66rpx;
} .tabbar_nav {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 20rpx;
height: 100%;
position: relative;
} .tabbar_btn {
padding: 0;
border: none;
background: #ff731d;
} .tabbar_icon {
width: 50rpx;
height: 50rpx;
} .special-wrapper {
position: absolute;
left: 77rpx;
top: -36rpx;
width: 96rpx;
height: 96rpx;
border-radius: 50%;
border-top: 2rpx solid #f2f2f3;
background-color: #fff;
text-align: center;
box-sizing: border-box;
padding: 6rpx;
} .special-wrapper .tabbar_icon {
width: 84rpx;
height: 84rpx;
} .special-text-wrapper {
width: 56rpx;
height: 56rpx;
}

三、页面调用

js

var app = getApp()
Page({
data: {
tabbar: {},
},
onLoad: function(options) {
app.editTabbar(); },
onReady: function () {
app.hideTabBar();
},
onShow: function () {
app.hideTabBar();
},

json

{
"enablePullDownRefresh": false,
"usingComponents": {
"tabbar": "../../tabbarComponent/tabbar"
}
}

wxml 底部添加

<tabbar tabbar="{{tabbar}}"></tabbar>

OK,万事大吉了

最后要说的没源码,没时间去弄

推荐一篇别人的写的:https://www.jianshu.com/p/2cd4a23b504b

微信小程序开发之自定义菜单tabbar的更多相关文章

  1. 微信小程序底部实现自定义动态Tabbar

    多图警告!!! 最近在工作中遇到这样一个需求:微信小程序底部的Tab需要通过判断登录人的角色动态进行改变,想要实现这个功能依靠小程序原生的Tabbar是不可能实现的了,所以研究了一下自定义Tab,这里 ...

  2. 手摸手教你微信小程序开发之自定义组件

    前言 相信大家在开发小程序时会遇到某个功能多次使用的情况,比如弹出框.这个时候大家首先想到的是组件化开发,就是把弹出框封装成一个组件,然后哪里使用哪里就调用,对,看来大家都是有思路的人,但是要怎样实现 ...

  3. 微信小程序开发之下拉菜单

    实现功能:点击维保人员,调出下拉菜单.选择子菜单时,显示右边的图标表示选中,并进行赋值并进行搜索筛选 Wxml: <view class="dtclass" bindtap= ...

  4. 微信小程序开发学习资料

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  5. 零基础入门微信小程序开发

    注:本文来源于:<零基础入门微信小程序开发> 课程介绍 本达人课是一个系列入门教程,目标是从 0 开始带领读者上手实战,课程以微信小程序的核心概念作为主线,介绍配置文件.页面样式文件.Ja ...

  6. 总结微信小程序开发中遇到的坑

    总结微信小程序开发中遇到的坑,一些坑你得一个一个的跳啊,/(ㄒoㄒ)/~~ 1,页面跳转和参数传递实例 首先说一下我遇到的需求有一个我的消息页面,里面的数据都是后端返回的,返回的数据大致如下,有一个是 ...

  7. 微信小程序开发中的二三事之网易云信IMSDK DEMO

    本文由作者邹永胜授权网易云社区发布. 简介 为了更好的展示我们即时通讯SDK强悍的能力,网易云信IM SDK微信小程序DEMO的开发就提上了日程.用产品的话说就是: 云信 IM 小程序 SDK 的能力 ...

  8. 《腾讯游戏人生》微信小程序开发总结

    为打通游戏人生擂台赛与线下商家的O2O衔接,同时响应时下日臻火热的微信小程序,项目团队决定也开发一款针对性的微信小程序,以此方便商家在我们平台入驻并进行擂台赛事的创建和奖励的核销,进一步推广擂台赛的玩 ...

  9. 我们的微信小程序开发

    基于微信小程序的系统开发准备工作 腾讯推出微信小程序也有一段时间了,在各种行业里面也都掀起一阵阵的热潮,很多APP应用被简化为小程序的功能迅速推出,同时也根据小程序的特性推出各种独具匠心的应用,相对传 ...

随机推荐

  1. VS2019 离线安装方法详解

    本文详细介绍了 VS2019 离线安装的相关步骤,以桌面开发为主下载 C++桌面开发..NET 桌面开发相关的工作负载.MFC 可选组件及帮助查看器. 工作负载(Workload) 离线安装需要先根据 ...

  2. 微信中如何做到访问app的下载链接时直接跳到默认浏览器去执行下载

    在我们使用微信营销的时候,很容易碰到H5链接在微信内无法打开或在微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢,主要有以下四点 1 ...

  3. pytorch识别CIFAR10:训练ResNet-34(自定义transform,动态调整学习率,准确率提升到94.33%)

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com 前面通过数据增强,ResNet-34残差网络识别CIFAR10,准确率达到了92.6. 这里对训练过程 ...

  4. 泛型与object

    一.泛型通俗的理解就是限制list集合里面的数据类型 比如List<int>,就限制LIST里面必须是int,这样放入其他就有报错(保证了安全),然后从 list里取元素,就不需要强制转化 ...

  5. 买房安全无忧 l 龙光集团与光大银行二手房资金监管战略合作!

    二手房买卖中,担心购房过程中房款交易的安全以致买方不敢先付款.卖方不敢先过户的现象比比皆是.近日,龙光集团与光大银行形成战略合作伙伴,联合推出“二手房交易资金监管”业务,彻底改变了二手房交易的付款模式 ...

  6. 常见排序算法总结:插入排序,希尔排序,冒泡排序,快速排序,简单选择排序以及java实现

    今天来总结一下常用的内部排序算法.内部排序算法们需要掌握的知识点大概有:算法的原理,算法的编码实现,算法的时空复杂度的计算和记忆,何时出现最差时间复杂度,以及是否稳定,何时不稳定. 首先来总结下常用内 ...

  7. OpenJudge-bailian 3454 秦腾与教学评估

    http://bailian.openjudge.cn/practice/3454?lang=en_US 题目 在秦腾进入北京大学学习的第一个学期,就不幸遇到了前所未有的教学评估.在教学评估期间,同学 ...

  8. python一(字符串,字典)

    list操作 name = ['小王','小米','小张','王强','张三','李四'] name.append('黄霑')#添加元素在最后一个 name.insert(,'王五')#指定下标插入元 ...

  9. MT【328】向量里的最佳逼近

    已知平面向量$\overrightarrow {a},\overrightarrow {b}$满足$|\overrightarrow {a}|=4,|\overrightarrow {b}|=2$.若 ...

  10. LOJ#2304 泳池

    题意:有一个1001 * n的矩形,每个位置有q的概率为1.求紧贴下边界的最大的全1子矩形面积恰为k的概率.n <= 1e9,k <= 1000. 解:只需考虑每一列最下面一个0的位置. ...