uniapp动态设置tabbar
创始人
2024-12-29 00:07:57
0
1、将所有需要的tabbar配置在pages.json里 
"tabBar": { 		"color": "#BEC0C3", 		"selectedColor": "#00A29C", 		"borderStyle": "#EEEEEE", 		"backgroundColor": "#ffffff", 		"list": [{ 				"pagePath": "pages/tabBar/devicePage", 				"iconPath": "static/image/tabbar/device.png", 				"selectedIconPath": "static/image/tabbar/device_active.png", 				"text": "设备" 			}, 			{ 				"pagePath": "pages/tabBar/voicePage", 				"iconPath": "static/image/tabbar/device.png", 				"selectedIconPath": "static/image/tabbar/device_active.png", 				"text": "语音" 			},  			{ 				"pagePath": "pages/tabBar/warnPage", 				"iconPath": "static/image/tabbar/warning.png", 				"selectedIconPath": "static/image/tabbar/warning_active.png", 				"text": "预警" 			}, { 				"pagePath": "pages/tabBar/locationPage", 				"iconPath": "static/image/tabbar/position.png", 				"selectedIconPath": "static/image/tabbar/position_active.png", 				"text": "位置" 			}, { 				"pagePath": "pages/tabBar/fencePage", 				"iconPath": "static/image/tabbar/fence.png", 				"selectedIconPath": "static/image/tabbar/fence_active.png", 				"text": "围栏" 			}, { 				"pagePath": "pages/tabBar/myPage", 				"iconPath": "static/image/tabbar/my.png", 				"selectedIconPath": "static/image/tabbar/my_active.png", 				"text": "我的" 			} 		] 	},

2、app.vue 的globalData里加入reviseTabbarByUserType方法

globalData: { 		reviseTabbarByUserType: function () { 			let isAdmin = uni.getStorageSync('isAdmin'); 			if (isAdmin == 1) { 				uni.setTabBarItem({ 					index: 1, 					visible: false, 				}) 			} else { 				uni.setTabBarItem({ 					index: 0, 					visible: false, 				}) 			} 		} 	},

3、涉及到的所有tabbar界面在onshow里调用reviseTabbarByUserType方法

onShow() { 		getApp().globalData.reviseTabbarByUserType(); 	},

###补充reviseTabbarByUserType方法解释

在uniapp中,reviseTabbarByUserType这个方法是用来根据用户类型修改TabBar的展示内容

  reviseTabbarByUserType(userType) {     const tabbar = {       list: [],     };          // 根据用户类型设置TabBar列表     if (userType === 'admin') {       tabbar.list = [         {           pagePath: '/pages/home/home',           text: '首页',         },         {           pagePath: '/pages/admin/admin',           text: '管理',         },       ];     } else {       tabbar.list = [         {           pagePath: '/pages/home/home',           text: '首页',         },         {           pagePath: '/pages/user/user',           text: '我的',         },       ];     }          // 修改TabBar     uni.setTabBarItem(tabbar);   }

     

相关内容

热门资讯

aapoker透明挂!wepo... aapoker透明挂!wepoke辅助(透视)一贯有挂(详细辅助重大通报)1、下载好aapoker透...
透视科技!智星德州菠萝插件官网... 透视科技!智星德州菠萝插件官网,aapoker透视插件,2025版教程(有挂黑科技)1、在智星德州菠...
wepoker透视脚本下载!h... wepoker透视脚本下载!hhpoker辅助挂(透视)确实是有挂(必赢教程)暗藏猫腻,小编详细说明...
透视透视!aapkoer德州辅... 1、透视透视!aapkoer德州辅助挂下载,智星菠萝辅助,2分钟细说(有挂技巧);该软件可以轻松地帮...
wpk真的有外挂!德州ai机器... wpk真的有外挂!德州ai机器人(透视)从前真的是有挂(详细辅助一分钟了解);一、wpk真的有外挂A...
透视教学!wpk透视脚本链接,... 透视教学!wpk透视脚本链接,hhpoker透视脚本下载,揭秘教程(有挂详情)hhpoker透视脚本...
红龙poker作弊指令!wep... 红龙poker作弊指令!wepoker底牌透视(透视)切实存在有挂(2025新版技巧)运红龙poke...
透视透视!aapoker辅助器... 透视透视!aapoker辅助器是真的吗,德普之星透视辅助ios,热点讨论(有挂了解)1、实时aapo...
德州ai机器人!微扑克有辅助挂... 德州ai机器人!微扑克有辅助挂(透视)切实是真的有挂(详细辅助一分钟了解)是一款可以让一直输的玩家,...
透视黑科技!aapoker辅助... 透视黑科技!aapoker辅助插件工具,wpk有没有脚本,可靠教程(有挂规律)1、下载好aapoke...