当前位置: 首页 > news >正文

uniapp自定义tabBar

uniapp自定义tabBar

1、在登录页中获取该用户所有的权限

getAppFrontMenu().then(res=>{if(res.length > 0){// 把所有权限存入缓存中let firstPath = res.reverse()[0].path;uni.setStorageSync('qx_data', res);uni.switchTab({url: firstPath,})// 方法二 通过uni.setTabBarItem()中visible属性设置(app端可以微信小程序端不行)//setTimeout(()=>{//	res.forEach( item => {//		uni.setTabBarItem({//		    index: item.priority,//		    visible: true//		})//	})//}, 500)} else {uni.switchTab({url:"/pages/my/index"})}})

2、page.json list添加所有要用到的页面

"tabBar":{"color": "#909199","selectedColor": "#FFFFFF","borderStyle": "black","backgroundColor": "#253C8C","list": [{"pagePath": "pages/index/index"// "iconPath": "static/image/tabIcon/home.png",// "selectedIconPath": "static/image/tabIcon/home_sel.png",// "text": "首页",// "visible": false},{"pagePath": "pages/monitor/index"// "iconPath": "static/image/tabIcon/yxjk.png",// "selectedIconPath": "static/image/tabIcon/yxjk_sel.png",// "text": "监控",// "visible": false},{"pagePath": "pages/data/data"// "iconPath": "static/image/tabIcon/sjfx.png",// "selectedIconPath": "static/image/tabIcon/sjfx_sel.png",// "text": "数据",// "visible": false},{"pagePath": "pages/order/index"// "iconPath": "static/image/tabIcon/ywgj.png",// "selectedIconPath": "static/image/tabIcon/ywgj_sel.png",// "text": "运维",// "visible": false},{"pagePath": "pages/my/index"// "iconPath": "static/image/tabIcon/my.png",// "selectedIconPath": "static/image/tabIcon/my_sel.png",// "text": "我的",// "visible": true}]},

3、在components文件夹中创建tabBer.vue

<template><!-- 自定义tabBar 组件 --><view class="tab-bar"><view class="content"><view class="one-tab" v-for="(item, index) in infoList" :key="index" @click="selectTabBar(item.pagePath)"><view><view class="tab-img"><image v-if="routePath === item.pagePath" class="img" :src="item.selectedIconPath"></image><image v-else class="img" :src="item.iconPath"></image></view></view><view :class="['tit', routePath === item.pagePath ? 'sel' : '']">{{ item.text }}</view></view></view></view>
</template><script>
export default {props: {// 当前页面路径routePath: {type: String,required: true}},data() {return {// 底部导航栏所有数据tabBarList:[{pagePath: "/pages/index/index",iconPath: require("../static/image/tabIcon/home.png"),selectedIconPath: require("../static/image/tabIcon/home_sel.png"),text: "首页"},{pagePath: "/pages/monitor/index",iconPath: require("../static/image/tabIcon/yxjk.png"),selectedIconPath: require("../static/image/tabIcon/yxjk_sel.png"),text: "监控"},{pagePath: "/pages/data/data",iconPath: require("../static/image/tabIcon/sjfx.png"),selectedIconPath: require("../static/image/tabIcon/sjfx_sel.png"),text: "数据"},{pagePath: "/pages/order/index",iconPath: require("../static/image/tabIcon/ywgj.png"),selectedIconPath: require("../static/image/tabIcon/ywgj_sel.png"),text: "运维"},{pagePath: "/pages/my/index",iconPath: require("../static/image/tabIcon/my.png"),selectedIconPath: require("../static/image/tabIcon/my_sel.png"),text: "我的"}],// 当前用户页面权限infoList: []};},mounted() {// 所有权限 主页面let qx_data = uni.getStorageSync('qx_data');if(qx_data && qx_data.length > 0){qx_data.forEach(item=>{this.infoList.push(this.tabBarList[item.priority]);})}else{// 如果没有选页面默认展示'我的'页面this.infoList.push(this.tabBarList[4]);}},methods: {selectTabBar(path) {uni.switchTab({url: path})console.log('path',path);}}
};
</script><style lang="scss" scoped>
.tab-bar {position: fixed;z-index: 1000;bottom: 0;left: 0;width: 100vw;padding: 0rpx;padding-bottom: calc(10rpx + constant(safe-area-inset-bottom));padding-bottom: calc(10rpx + env(safe-area-inset-bottom));background-color: #253C8C;color: #909199;padding-top: 12rpx;.content {display: flex;flex-direction: row;.one-tab {display: flex;flex-direction: column;align-items: center;width: 100%;.tab-img {width: 50rpx;height: 50rpx;.img {width: 100%;height: 100%;}}.tit {font-size: 25rpx;transform: scale(0.7);}.sel {color: #FFFFFF;}}}}
</style>

4、在每个主页面中使用(pages/index/index.vue)导入 注册 使用 其他主页面同理 只需替换每个页面的routePath

<!-- 自定义tabBar -->
<tabBer routePath="/pages/index/index"/>
import tabBer from '@/components/tabBer.vue'; 
components: {// #ifdef MP-WEIXINcircleProgress,// #endif// #ifdef APP-PLUSupdatedVersion,// #endifselectpopup,areaweather,tabBer},

5、在最后App.vue中

onShow: function() {// 将默认的原生tabbar隐藏 uni.hideTabBar();},

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • unity2022 il2cpp 源码编译
  • 信息检索(39):Condenser: a Pre-training Architecture for Dense Retrieval
  • SpringBoot源码深度解析
  • # Redis 入门到精通(九)-- 主从复制(1)
  • buu做题(6)
  • 时间卷积网络(TCN):序列建模的强大工具(附Pytorch网络模型代码)
  • 入门 git
  • MySQL:SELECT 语句
  • Android 11 HAL层集成FFMPEG
  • Flink源码学习资料
  • 机体坐标系和导航坐标系
  • 【中项】系统集成项目管理工程师-第2章 信息技术发展-2.1信息技术及其发展-2.1.1计算机软硬件与2.1.2计算机网络
  • springboot防止重复提交的方案有哪些
  • [2019红帽杯]Snake
  • 纯前端导出xlsx表格
  • 深入了解以太坊
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • 【Amaple教程】5. 插件
  • CentOS从零开始部署Nodejs项目
  • java多线程
  • java中具有继承关系的类及其对象初始化顺序
  • mysql中InnoDB引擎中页的概念
  • scala基础语法(二)
  • Vue2 SSR 的优化之旅
  • 动态魔术使用DBMS_SQL
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 技术胖1-4季视频复习— (看视频笔记)
  • 简单数学运算程序(不定期更新)
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 视频flv转mp4最快的几种方法(就是不用格式工厂)
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 微服务入门【系列视频课程】
  • 一天一个设计模式之JS实现——适配器模式
  • 优秀架构师必须掌握的架构思维
  • 再谈express与koa的对比
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 2017年360最后一道编程题
  • # Redis 入门到精通(八)-- 服务器配置-redis.conf配置与高级数据类型
  • #QT 笔记一
  • (3)STL算法之搜索
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • (六)什么是Vite——热更新时vite、webpack做了什么
  • (四)软件性能测试
  • (一)kafka实战——kafka源码编译启动
  • (一)基于IDEA的JAVA基础12
  • (转)C#开发微信门户及应用(1)--开始使用微信接口
  • (转)fock函数详解
  • (转)IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
  • (转)linux自定义开机启动服务和chkconfig使用方法
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .bat批处理(三):变量声明、设置、拼接、截取
  • .NET CF命令行调试器MDbg入门(一)
  • .NET 回调、接口回调、 委托
  • .NET 自定义中间件 判断是否存在 AllowAnonymousAttribute 特性 来判断是否需要身份验证