uniapp 实现小程序中自定义tabBar 的方法
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 的方法的更多相关文章
- 微信小程序中自定义modal
微信小程序中自定义modal .wxml <modal hidden="{{hidden}}" title="这里是title" confirm-text ...
- 【小程序】小程序中设置 tabBar
小程序中 tabBar 的设置,tabBar 就是底部导航栏,在app.json中配置. list 为数组至少两项.tab栏的 position 为 top 时间,不显示图标. "tabBa ...
- 微信小程序中的tabBar设置
我们先来看一份图,这个设置在官方文档中已经写得很清楚了,我只是做一个总结 注:我写注释是为了方便说明,在小程序中的json文件中是不能用注释的 这个tabBar属于全局属性,因此就在全局配置文件app ...
- 微信小程序中自定义swiper轮播图面板指示点的样式
重置样式: .swiper{ width: 100%; height: 240px; margin-bottom: 0.5rem; position:relative; } div.wx-swiper ...
- 微信小程序中自定义函数的学习使用
新手,最近在给学校搞个党费计算器.需要自己定义函数来实现某个功能. 1.无参函数: 函数都是写在js文件里面的. Page({ data:{ income1:'0', }, cal:function( ...
- 小程序 之自定义tabbar上边框颜色
一.设置borderStyle 二.设置page样式 page::after{ content: ''; position: fixed; left: 0; bottom: 0; width: 100 ...
- 微信小程序中的自定义组件
微信小程序中的组件 前言 之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 ...
- taro中自定义tabbar实现中间图标凸出效果
遇到的一个需求是在tabbar上有一个凸起的小图标, 但是微信自带的tabbar是没有这个效果的, 无奈,只能使用自定义tabbar,查找了多方文档后发现大多是原生小程序实现, 关于taro文档的少之 ...
- 微信小程序中的组件
前言 之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 1.6.3 开始,官 ...
- 微信小程序中的自定义组件(components)
其实小程序开发很像vue和react的结合,数据绑定和setData 重新渲染页面的数据,最近发现连写组件都是很像,也是醉了,自我认为哈, 因为小程序可以将页面内的功能模块抽象成自定义组件,以便在 ...
随机推荐
- Centos_yum使用
安装应用 yum install -y xxx -y 表示自动yes 卸载应用 yum -y remove xxx -y 表示自动yes 查看已安装的应用 yum list installed
- Spark 读取HDFS csv文件并写入hive
package com.grady import org.apache.spark.SparkConf import org.apache.spark.sql.{Row, SaveMode, Spar ...
- 思维导图学《On Java》基础卷 + 进阶卷
说明 目录 思维导图 导读 第 1 章 什么是对象 第 3 章 一切都是对象 第 6 章 初始化和清理 第 7 章 实现隐藏 第 8 章 复用 第 9 章 多态 第 10 章 接口 第 11 章 内部 ...
- kubernetes中部署kube-prometheus项目解决ControllerManager与Scheduler无法监控问题
文章转载自:https://www.kococ.cn/20210302/cid=697.html 一.问题描述 在部署 kube-prometheus 到 kubernetes 集群中总会遇到一个问题 ...
- ProxySQL(2):初试读写分离
文章转载自:https://www.cnblogs.com/f-ck-need-u/p/9278839.html 实现一个简单的读写分离 这里通过一个简单的示例实现ProxySQL的读写分离功能,算是 ...
- Elasticsearch 堆内存
转载自:https://www.lbbniu.com/6148.html 1.什么是堆内存? Java 中的堆是 JVM 所管理的最大的一块内存空间,主要用于存放各种类的实例对象. 在 Java 中, ...
- Elastic:使用Grafana监视 Elasticsearch
- aardio + PowerShell 可视化快速开发独立 EXE 桌面程序
aardio 可以方便地调用 PowerShell ,PowerShell 中也可以自由调用 aardio 对象与函数.不用带上体积很大的System.Management.Automation.dl ...
- 「产品运营」研发效能之DevOps平台如何运营?
有人常说「酒香不怕巷子深」.不是的,如果这个巷子是酒吧街,那最深的那家酒吧肯定是租金最便宜的.酒吧的地段好坏已经在租金价格上体现出来了.现在已经不是那个工具缺乏.有个工具就拍手称快.欣然去试用的时代了 ...
- .NET下数据库的负载均衡(有趣实验)(续)
.NET下数据库的负载均衡(有趣实验)这篇文章发表后,受到了众多读者的关注与好评,其中不乏元老级程序员. 读者来信中询问最多的一个问题是:它是否能支持"异种数据库"的负载均衡?? ...