uni.setTabBarBadge update invalid problem on non-tabbar pages

 

The official recommendation is to use caching, which can calculate the effective number of shopping carts in real time through vuex getters .

Use the onShow hook on each tabbar page to update the latest cart quantity to the tabbar corner

settabbar.js 

import store from '@/store'
export default function tabBarBadgeSync() {
    if (store.state.token) {
        if (store.state.messageinfo.UnReadCNT < 1) {
            return uni.removeTabBarBadge({
                index: 2,
            });
        }
        setTimeout(() => {
            uni.setTabBarBadge({
                index: 2,
                text: store.state.messageinfo.UnReadCNT + "",
            });
        }, 100);
       
    }
}

How to use

import tabBarBadgeSync from '@/utils/settabbar.js';

onShow() {
	tabBarBadgeSync.call(this)
},

 

Guess you like

Origin blog.csdn.net/QQ_Empire/article/details/128386809