uniapp 实现小程序中自定义tabBar 的方法

第一种方式: page.json中配置

"tabBar": {
"color": "#7A7E83",
"selectedColor": "#007AFF",
"borderStyle": "black",
"backgroundColor": "#F8F8F8",
"fontSize": "12px",
"spacing": "5px",
"height": "50px",
"list" : [
{
"pagePath": "pages/index/index",
"text": "头像",
"iconPath": "static/down.png",
"selectedIconPath": "static/down.png"
},
{
"pagePath": "pages/bizhi/index",
"text": "壁纸",
"iconPath": "static/bizhi.png",
"selectedIconPath": "static/bizhi.png"
},
{
"pagePath": "pages/zhenjian/index",
"text": "证件照",
"iconPath": "static/zhenjian.png",
"selectedIconPath": "static/zhenjian.png"
},
{
"pagePath": "pages/zhenjian/index",
"text": "头像易",
"iconPath": "static/txy.png",
"selectedIconPath": "static/txy.png"
}
]
},

定义的内容需要在pages 中声明了。

这种方式定义比较快速,简单。

如果需要根据用户权限,或者在tabBar 上自定义一些逻辑,需要使用自定义的内容

第二种方式 自定义内容

<template>
<view class="tab-bar">
<view v-for="(item,index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
<image class="tab_img" :src="selected === index ? item.selectedIconPath : item.iconPath"></image>
<view class="tab_text" :style="{color: selected === index ? selectedColor : color}">{{item.text}}</view>
</view>
</view>
</template>
<script>
export default {
props: {
selected: { // 当前选中的tab index
type: Number,
default: 0
},
},
data() {
return {
color: "#333333",
selectedColor: "#d4237a",
list: [
{
"pagePath": "pages/index/index",
"text": "头像",
"iconPath": "https://bj.bcebos.com/txy-dev/txy/main/down.png",
"selectedIconPath": "https://bj.bcebos.com/txy-dev/txy/main/down.png"
},
{
"pagePath": "pages/bizhi/index",
"text": "壁纸",
"iconPath": "https://bj.bcebos.com/txy-dev/txy/main/bizhi.png",
"selectedIconPath": "https://bj.bcebos.com/txy-dev/txy/main/bizhi.png"
},
{
"pagePath": "pages/bizhi/index",
"text": "证件照",
"iconPath": "https://bj.bcebos.com/txy-dev/txy/main/zhenjian.png",
"selectedIconPath": "https://bj.bcebos.com/txy-dev/txy/main/zhengjian.png"
},
{
"pagePath": "pages/bizhi/index",
"text": "头像易",
"iconPath": "https://bj.bcebos.com/txy-dev/txy/main/txy.png",
"selectedIconPath": "https://bj.bcebos.com/txy-dev/txy/main/txy.png"
}
]
}
},
methods: {
switchTab(item, index) {
console.log("item", item)
console.log("index", index)
let url = item.pagePath;
// 对应患者和医生的首页
if (index == 0) {
url = "/pages/index/index"
}
// 对应患者和医生的我的页面
if (index == 1) {
url = "/pages/bizhi/index"
}
if (index == 2) {
uni.navigateToMiniProgram({
appId: 'wxac06eaffe466baa3',
})
// wxacd92e691aba23dd
// wxac06eaffe466baa3
return
}
if (index == 3) {
uni.navigateToMiniProgram({
appId: 'wxacd92e691aba23dd',
})
// wxacd92e691aba23dd
// wxac06eaffe466baa3
return
}
uni.switchTab({
url
})
}
}
}
</script> <style lang="less">
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100rpx;
background: white;
display: flex;
justify-content: center;
align-items: center;
padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column; .tab_img {
width: 37rpx;
height: 41rpx;
} .tab_text {
font-size: 20rpx;
margin-top: 9rpx;
}
}
}
</style>

在需要用到tabBar 的页面 引用。 并且需要关闭第一种方法中默认的

onShow() {
uni.hideTabBar({
animation: false
})
},

下面是我的小程序体验码,希望能和大家共同学习进步

[项目代码] https://gitee.com/eyes-star/txy-openmp.git

[项目代码] https://gitee.com/eyes-star/zjz-openmp.git

uniapp 实现小程序中自定义tabBar 的方法的更多相关文章

  1. 微信小程序中自定义modal

    微信小程序中自定义modal .wxml <modal hidden="{{hidden}}" title="这里是title" confirm-text ...

  2. 【小程序】小程序中设置 tabBar

    小程序中 tabBar 的设置,tabBar 就是底部导航栏,在app.json中配置. list 为数组至少两项.tab栏的 position 为 top 时间,不显示图标. "tabBa ...

  3. 微信小程序中的tabBar设置

    我们先来看一份图,这个设置在官方文档中已经写得很清楚了,我只是做一个总结 注:我写注释是为了方便说明,在小程序中的json文件中是不能用注释的 这个tabBar属于全局属性,因此就在全局配置文件app ...

  4. 微信小程序中自定义swiper轮播图面板指示点的样式

    重置样式: .swiper{ width: 100%; height: 240px; margin-bottom: 0.5rem; position:relative; } div.wx-swiper ...

  5. 微信小程序中自定义函数的学习使用

    新手,最近在给学校搞个党费计算器.需要自己定义函数来实现某个功能. 1.无参函数: 函数都是写在js文件里面的. Page({ data:{ income1:'0', }, cal:function( ...

  6. 小程序 之自定义tabbar上边框颜色

    一.设置borderStyle 二.设置page样式 page::after{ content: ''; position: fixed; left: 0; bottom: 0; width: 100 ...

  7. 微信小程序中的自定义组件

    微信小程序中的组件 前言 之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 ...

  8. taro中自定义tabbar实现中间图标凸出效果

    遇到的一个需求是在tabbar上有一个凸起的小图标, 但是微信自带的tabbar是没有这个效果的, 无奈,只能使用自定义tabbar,查找了多方文档后发现大多是原生小程序实现, 关于taro文档的少之 ...

  9. 微信小程序中的组件

    前言 之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 1.6.3 开始,官 ...

  10. 微信小程序中的自定义组件(components)

     其实小程序开发很像vue和react的结合,数据绑定和setData  重新渲染页面的数据,最近发现连写组件都是很像,也是醉了,自我认为哈, 因为小程序可以将页面内的功能模块抽象成自定义组件,以便在 ...

随机推荐

  1. KingbaseES V8R6C5禁用root用户ssh登录图形化部署集群案例

    案例说明: 对于KingbaseES V8R6C5版本在部集群时,需要建立kingbase.root用户在节点间的ssh互信,如果在生产环境禁用root用户ssh登录,则通过ssh部署会失败:在图形化 ...

  2. 采云链SRM SaaS供应商管理系统,发展型中小企业的福音

    采购业务的发展遵循一些规律:采购从一开始围绕"供应商"开展,逐渐发展成围绕"货物"进行,如今围绕"供应商协同"和"采购流程管理&q ...

  3. Windows服务器无法配置IP

    前天在给一台服务器配置IP地址的时候发现一个奇怪的问题.IP地址配置之后不生效,还是使用的169.254这个微软保留自动分配地址.由于这个是一台虚拟机,尝试了删除添加网卡也没有用.配置IP不成功的时候 ...

  4. 《Java基础——方法的调用》

    Java基础--方法的调用     总结: 1. 在同一个类中-- 对于静态方法,其它的静态和非静态方法都可以直接通过"方法名"或者"类名.方法名"调用它. 对 ...

  5. 使用 Loki 微服务模式部署生产集群

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247500523&idx=1&sn=0994af2b50 ...

  6. 使用kubeoperator安装k8s集群时自带的traefik-ingress-controller

    前提 承接上一篇文章:https://www.cnblogs.com/sanduzxcvbnm/p/15740596.html traefik-ingress-controller和nginx-ing ...

  7. 部署文件:filebeat->kafka集群(zk集群)->logstash->es集群->kibana

    该压缩包内包含以下文件: 1.install_java.txt 配置java环境,logstash使用 2.es.txt 三节点的es集群 3.filebeat.txt 获取日志输出到kafka集群 ...

  8. 单台主机MySQL多实例部署

    二进制安装mysql-5.7.26 [root@mysql ~]# cd /server/tools/ [root@mysql tools]# ll total 629756 -rw-r--r-- 1 ...

  9. 使用cnpm创建vue项目(含离线安装)

    # 全局安装淘宝cnpm npm install -g cnpm --registry=https://registry.npm.taobao.org #升级 npm cnpm install npm ...

  10. JavaScript 的闭包(closure)

    以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「englyf」https://www.cnblogs.com/englyf/ 对于闭包的理解,其实可以归纳为,在创建函数时,同时创建了一 ...