Explorar o código

fix(tabbar): 修复H5环境下无tabbar时的白屏问题

当tabbar缓存未启用时,将tabBar配置设为undefined而非空对象。在H5环境下,无tabbar时设置为空对象以防止浏览器报错导致白屏
feige996 hai 8 meses
pai
achega
c31090e389
Modificáronse 2 ficheiros con 4 adicións e 2 borrados
  1. 3 1
      pages.config.ts
  2. 1 1
      src/tabbar/config.ts

+ 3 - 1
pages.config.ts

@@ -1,3 +1,4 @@
+import { isH5 } from '@uni-helper/uni-env'
 import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
 import { tabBar } from './src/tabbar/config'
 
@@ -19,5 +20,6 @@ export default defineUniPages({
     },
   },
   // tabbar 的配置统一在 “./src/tabbar/config.ts” 文件中
-  tabBar: tabBar as any,
+  // 无tabbar模式下,h5 设置为 {} 为了防止浏览器报错导致白屏
+  tabBar: tabBar || (isH5 ? {} : undefined) as any,
 })

+ 1 - 1
src/tabbar/config.ts

@@ -153,4 +153,4 @@ const _tabbar: TabBar = {
 }
 
 // 0和1 需要显示底部的tabbar的各种配置,以利用缓存
-export const tabBar = tabbarCacheEnable ? _tabbar : {}
+export const tabBar = tabbarCacheEnable ? _tabbar : undefined