收藏
回答

uniapp微信小程序自定义tabBar切换时会闪烁一下?

微信小程序自定义tabBar切换时会闪烁一下

怎么解决

回答关注问题邀请回答
收藏

4 个回答

  • Bo👑
    Bo👑
    2025-05-13

    在App.vue 中添加

    globalData: {

    tabindex: 0, // tabbar对应下标

    },

    在custom-tab-bar index.js 中添加 attached 并在switchTab 方法中修改 globalData.tabindex

    代码如下:

    lifetimes: {
    		attached: function () {
    			if (typeof app.globalData.tabindex !== 'undefined' && this.data.selected !== app.globalData.tabindex) {
    				console.log('tabindex changed:', app.globalData.tabindex)
    				this.setData({
    					selected: app.globalData.tabindex
    				})
    			}
    		}
    	},
    methods: {
    		switchTab(e) {
    			const {
    				index,
    				path
    			} = e.currentTarget.dataset
    			const url = path
    			wx.switchTab({
    				url: `/${url}`
    			})
    			app.globalData = {
    				tabindex: index
    			}
    		}
    	}
    
    



    2025-05-13
    有用 1
    回复
  • 衣殇魂
    衣殇魂
    2024-06-26

    用uView的底部导航栏组件,https://v1.uviewui.com/components/tabbar.html

    2024-06-26
    有用
    回复
  • showms
    showms
    2024-06-26

    老问题,暂时没有解决方案

    2024-06-26
    有用
    回复
  • 小胖
    小胖
    2024-06-26

    试下wx.setNavigationBarTitle更新标题,不写在json里面

    2024-06-26
    有用
    回复
登录 后发表内容