zhangwencui
2 天以前 f670b79094c95d791fc43c8fc8b5858ebf8426dc
src/pages/message.vue
@@ -233,6 +233,16 @@
    return null;
  };
  // tabbar 角标:异步返回时可能已切到非 tabBar 页面,失败静默忽略
  const callTabBarApi = (api, options) => {
    try {
      const ret = uni[api](options);
      if (ret && typeof ret.catch === "function") ret.catch(() => {});
    } catch (e) {
      /* 非 tabBar 页面,忽略 */
    }
  };
  // 更新 tab 栏角标
  const updateTabBarBadge = () => {
    if (userId.value) {
@@ -241,12 +251,12 @@
          const count = res.data || 0;
          // 更新tabbar的角标
          if (count > 0) {
            uni.setTabBarBadge({
            callTabBarApi("setTabBarBadge", {
              index: 2, // 消息标签页的索引
              text: count.toString(),
            });
          } else {
            uni.removeTabBarBadge({
            callTabBarApi("removeTabBarBadge", {
              index: 2,
            });
          }