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

uniapp自定义权限菜单,动态tabbar

已封装为组件,亲测4个菜单项目可以切换,

以下为示例,根据Storage 中 userType 的 值,判断权限菜单

<template><view class="tab-bar pb10"><view class="tabli" v-for="(tab, index) in tabs" :key="index" @click="switchTab(tab)"><image :src="currentTab === tab.text ? tab.selectedIconPath : tab.iconPath" mode="aspectFit"></image><text :class="currentTab === tab.text ? 'active' : ''">{{ tab.text }}</text></view><loginTourist ref="loginPop"></loginTourist></view>
</template>
<script>
export default {props: {//当前页currentTab: {type: String,required: true}},data() {return {// 游客、管理员、村民usertype: uni.getStorageSync('userType'),}},
computed: {// 权限菜单tabs() {if (this.usertype =='村民') {return [{"pagePath": "/pages/homepage/index","iconPath": this.img('home-1'),"selectedIconPath": this.img('home'),"text": "首页"},
{"pagePath": "/workPages/teach/index","iconPath": this.img('bs-1'),"selectedIconPath": this.img('bs'),"text": "办事指南"},{"pagePath": "/pages/messag/index","iconPath": this.img('mass-1'),"selectedIconPath": this.img('mass'),"text": "消息"},{"pagePath": "/pages/mine/index","iconPath": this.img('mine-1'),"selectedIconPath": this.img('mine'),"text": "我的"}],}else if (this.usertype =='管理员') {// 管理员return [{"pagePath": "/pages/homepage/index","iconPath": this.img('home-1'),"selectedIconPath": this.img('home'),"text": "首页"}, ],}}},
methods: {switchTab(tab) {// console.log("底部导航", tab)let userType = uni.getStorageSync('userType')||this.userTypelet token = uni.getStorageSync('token')console.log('底部导航,用户,token|',tab.text ,userType,token)uni.navigateTo({url: tab.pagePath});},// 统一加图片域名路径img(img) {return 图片网址前缀 + 'tabBar/' + img + '.png'},},</script>
<style>.tab-bar {justify-content: space-around;align-items: center;height: 150upx;position: fixed;left: 0;z-index: 99999999999999999999;width: 100%;display: flex;justify-content: space-around;background: rgb(240 242 245 / 97%);border-top: 0.5px solid rgba(240, 242, 245, 1)}.tab-bar .tabli {flex: 1;display: flex;flex-direction: column;align-items: center;
justify-content: center;}.tab-bar image {width: 25px;height: 25px;}.tab-bar text {font-size: 12px;margin-top: 5px;}.tab-bar text.active {font-weight: bold;}
</style>

声明为全局组件:main.js 中添加

import tzTabBar from "@/components/atz-tabbar/atz-tabbar.vue"//自定义底部菜单
Vue.component('tzTabBar', tzTabBar)

在页面中使用:

<tzTabBar :currentTab="'消息'"></tzTabBar>

http://www.lryc.cn/news/216289.html

相关文章:

  • ubuntu20.04配置解压版mysql5.7
  • 【js】vue获取document.getElementById(a)为null
  • 系列六、Mybatis的一级缓存
  • 用中文编程工具给澳大利亚客户定制开发的英文版服装进销存软件应用实例
  • geoserver 的跨域问题怎么解决
  • SQL语法实践(一)
  • 路由器如何设置IP地址
  • 自动驾驶算法(一):Dijkstra算法讲解与代码实现
  • MS5910PA为行业内领先的可配置10bit到16bit分辨率的旋变数字转换器,可替代AD2S1210
  • Random指定随机种子遇到的坑
  • 2023云栖大会:属于开发者的狂欢
  • jsp 网上订餐Myeclipse开发mysql数据库web结构java编程计算机网页项目
  • 优化大表分页查询性能:大表LIMIT 1000000, 10该怎么优化?
  • ubuntu PX4 vscode stlink debug设置
  • Flask的一种启动方式和三种托管方式
  • cudnn too short
  • 01、SpringBoot + MyBaits-Plus 集成微信支付 -->项目搭建
  • Linux 性能调优之网络优化
  • RT-Thread系统使用常见问题处理记录
  • 优先队列----数据结构
  • nginx项目部署教程
  • 资源限流 + 本地分布式多重锁——高并发性能挡板,隔绝无效流量请求
  • day52【子序列】300.最长递归子序列 674.最长连续递增序列 718.最长重复子数组
  • 计算机视觉 计算机视觉识别是什么?
  • Make.com实现多个APP应用的自动化的入门指南
  • LLMs之HFKR:HFKR(基于大语言模型实现异构知识融合的推荐算法)的简介、原理、性能、实现步骤、案例应用之详细攻略
  • 多模态 多引擎 超融合 新生态!2023亚信科技AntDB数据库8.0产品发布
  • elasticsearch无法访问9200端口
  • 【Linux】进程等待
  • 电视「沉浮录」:跌出家电“三大件”?