uniapp tabbar权限问题

在app.vue里添加:

export default {
//在此处添加一个函数 globalData: {
//更改tabbar权限 reviseTabbarByUserType: function() {
         //可以写自己的逻辑代码
// let username = uni.getStorageSync('login_user_info').username; // if (username != 'admin') { // uni.setTabBarItem({ // index: 1, // visible: false, // }) // } else { // uni.setTabBarItem({ // index: 1, // visible: true, // }) // }
              uni.setTabBarItem({
                            index: 1,
                            visible: true,
                        })
                        uni.setTabBarItem({
                            index: 2,
                            visible: true,
                        })
                        uni.setTabBarItem({
                            index: 0,
                            visible: true,
                        })
} },
uni.setTabBarItem() 是一个uni-app框架提供的API,用于设置底部导航栏的某个tab的样式和属性。其中,index表示要设置的tab的索引,visible表示该tab是否可见。在上述代码中,uni.setTabBarItem({index: 1, visible: false})表示将底部导航栏的第二个tab设置为不可见。

 在onShow()里面写上getApp().globalData.reviseTabbarByUserType();!!!!!

如果想要显示tabbar然后点击其他的tabbar显示无权限登录然后不跳转,就要用到tabbar点击事件

onTabItemTap : function(e) {
            console.log(e);
            if(this.menu.length === 0){
                setTimeout(() => {
                        uni.showToast({
                          title: '暂无权限!',
                          icon: 'none',
                          // duration: 100
                        })
                      }, 500);
                      uni.switchTab({
                          url:'/pages/setting/setting'
                      })
                return false
            }
        },

posted @ 2023-12-07 09:59  prince11  阅读(130)  评论(0编辑  收藏  举报