diff --git a/src/tabbar/config.ts b/src/tabbar/config.ts index a22521d..c088106 100644 --- a/src/tabbar/config.ts +++ b/src/tabbar/config.ts @@ -1,9 +1,9 @@ import type { TabBar } from '@uni-helper/vite-plugin-uni-pages' type FgTabBarItem = TabBar['list'][0] & { - iconType: 'uniUi' | 'uiLib' | 'unocss' | 'iconfont' | 'local' + iconType: 'uniUi' | 'uiLib' | 'unocss' | 'iconfont' | 'image' icon: any // 其实是 string 类型,这里是为了避免 ts 报错 - activeIcon?: string // 只有在 local 模式下才需要,传递的是高亮的图片(PS: 不建议用 local 模式) + activeIcon?: string // 只有在 image 模式下才需要,传递的是高亮的图片(PS: 不建议用 image 模式) } /** @@ -79,7 +79,7 @@ export const tabbarList: FgTabBarItem[] = [ // text: '首页', // // 使用 ‘local’时,需要配置 icon + iconActive 2张图片(不推荐) // // 既然已经用了自定义tabbar了,就不建议用图片了,所以不推荐 - // iconType: 'local', + // iconType: 'image', // icon: '/static/tabbar/home.png', // iconActive: '/static/tabbar/homeHL.png', // }, diff --git a/src/tabbar/index.vue b/src/tabbar/index.vue index 58d76d4..60d3419 100644 --- a/src/tabbar/index.vue +++ b/src/tabbar/index.vue @@ -44,7 +44,11 @@ function getColorByIndex(index: number) { return tabbarStore.curIdx === index ? activeColor : inactiveColor } -function getImageByIndex(index: number, item: { iconActive: string, icon: string }) { +function getImageByIndex(index: number, item: { iconActive?: string, icon: string }) { + if (!item.iconActive) { + console.warn('image 模式下,需要配置 iconActive,否则无法切换图片') + return item.icon + } return tabbarStore.curIdx === index ? item.iconActive : item.icon } @@ -72,7 +76,7 @@ function getImageByIndex(index: number, item: { iconActive: string, icon: string -