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);   }

     

相关内容

热门资讯

透视好友!德普之星辅助软件(透... 透视好友!德普之星辅助软件(透视)app安卓版破解版(果然是真的有挂)1、德普之星辅助软件ai辅助优...
透视数据!wpk透视辅助靠谱吗... 透视数据!wpk透视辅助靠谱吗(透视)插件(都是真的有挂)1、完成wpk透视辅助靠谱吗的残局,帮助玩...
透视科技!wepoker透视脚... 透视科技!wepoker透视脚本免费(透视)辅助器可以弄(总是有挂)1、完成wepoker透视脚本免...
透视挂透视!wepoker透视... 透视挂透视!wepoker透视是真的吗(透视)poker辅助器免费安装(真是真的有挂)所有人都在同一...
透视安装!德普之星辅助工具如何... 透视安装!德普之星辅助工具如何打开(透视)透视(本来是有挂);1、任何德普之星辅助工具如何打开ai辅...
透视存在!wpk俱乐部是做什么... 透视存在!wpk俱乐部是做什么的(透视)透视插件(果然真的有挂);1、点击下载安装,wpk俱乐部是做...
透视安装!wepoker作弊方... 透视安装!wepoker作弊方法(透视)辅助器(本来是有挂);wepoker作弊方法软件透明挂微扑克...
透视游戏!wepoker国外版... 透视游戏!wepoker国外版透视(透视)wepoker有辅助吗(其实是真的有挂)1、很好的工具软件...
透视免费!德普之星私人局透视(... 透视免费!德普之星私人局透视(透视)app安卓版破解版(果然是有挂);运德普之星私人局透视辅助工具,...
透视ai!wpk私人局辅助是真... 透视ai!wpk私人局辅助是真的吗(透视)辅助(都是真的是有挂)1、构建自己的wpk私人局辅助是真的...