Skip to content

Tabbar

基础用法

html

<pa-tabbar v-model="active" :fixed="false" :safe-area-inset-bottom="false">
  <pa-tabbar-item icon="home" text="首页"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息"></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref(0)

通过名称匹配

html

<pa-tabbar v-model="active" :fixed="false" :safe-area-inset-bottom="false">
  <pa-tabbar-item icon="home" text="首页" name="home"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息" name="message"></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单" name="cart"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置" name="setting"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref('home')

徽标提示

html

<pa-tabbar v-model="active" :fixed="false" :safe-area-inset-bottom="false">
  <pa-tabbar-item icon="home" text="首页"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息" dot></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单" info="5"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置" info="99"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref(0)

自定义图标

html

<!-- 图片如果自带留白,可以尺寸设置大一点,然后将和间距调小一点(如下示例),保证核心图标大小为22px左右视觉效果最佳 -->
<pa-tabbar
  v-model="tabbarActive"
  :fixed="false"
  :safe-area-inset-bottom="false"
  style="--pa-tabbar-item-icon-margin-bottom: 1px"
>
  <pa-tabbar-item text="首页" info="6">
    <template #icon="{ active }">
      <image v-if="active" src="../../images/menu_active.png" style="width: 25px; height: 25px" />
      <image v-else src="../../images/menu_normal.png" style="width: 25px; height: 25px" />
    </template>
  </pa-tabbar-item>
  <pa-tabbar-item text="订单">
    <template #icon="{ active }">
      <image v-if="active" src="../../images/cart_active.png" style="width: 25px; height: 25px" />
      <image v-else src="../../images/cart_normal.png" style="width: 25px; height: 25px" />
    </template>
  </pa-tabbar-item>
  <pa-tabbar-item text="消息">
    <template #icon="{ active }">
      <image v-if="active" src="../../images/sale_active.png" style="width: 25px; height: 25px" />
      <image v-else src="../../images/sale_normal.png" style="width: 25px; height: 25px" />
    </template>
  </pa-tabbar-item>
  <pa-tabbar-item text="我的">
    <template #icon="{ active }">
      <image v-if="active" src="../../images/user_active.png" style="width: 25px; height: 25px" />
      <image v-else src="../../images/user_normal.png" style="width: 25px; height: 25px" />
    </template>
  </pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const tabbarActive = ref(0)

自定义颜色

html

<pa-tabbar
  v-model="active"
  :fixed="false"
  :safe-area-inset-bottom="false"
  active-color="var(--pa-color-danger)"
  inactive-color="#000"
>
  <pa-tabbar-item icon="home" text="首页"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息"></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref(0)

监听事件

html

<pa-tabbar v-model="active" :fixed="false" :safe-area-inset-bottom="false" @change="onChange">
  <pa-tabbar-item icon="home" text="首页"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息"></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref(0)

const onChange = (name: string | number) => {
  uni.showToast({
    title: `切换到第${name}个标签`,
    icon: 'none',
  })
}

固定在底部

html

<view style="height: 300px"></view>
<pa-tabbar v-model="active" placeholder>
  <pa-tabbar-item icon="home" text="首页"></pa-tabbar-item>
  <pa-tabbar-item icon="message" text="消息"></pa-tabbar-item>
  <pa-tabbar-item icon="cart" text="订单"></pa-tabbar-item>
  <pa-tabbar-item icon="setting" text="设置"></pa-tabbar-item>
</pa-tabbar>
ts

import { ref } from 'vue'

const active = ref(0)

Tabbar Props

参数说明类型默认值
modelValue当前选中标签的索引string | number-
fixed是否固定在底部booleantrue
placeholder固定在底部时,是否在标签位置生成一个等高的占位元素boolean-
border是否展示外边框booleantrue
zIndex元素层级z-indexnumber1
activeColor选中标签的颜色string-
inactiveColor未选中标签的颜色string-
safeAreaInsetBottom是否为 iPhoneX 留出底部安全距离booleantrue

TabbarItem Props

参数说明类型默认值
name标签名称,作为匹配的标识符string | number-
text标签标题string-
icon图标名称,可选值见 Icon 组件string-
iconPrefix图标类名前缀,同 Icon 组件的 class-prefix 属性string-
dot是否显示小红点boolean-
info图标右上角提示信息string-
url点击后跳转的链接地址, 需要以 / 开头string-
linkType链接跳转类型,可选值为 redirectTo、switchTab、reLaunch'redirectTo'|'switchTab'|'reLaunch''switchTab'

Tabbar Event

事件名参数
update:modelValue(name: string | number)
change(name: string | number)

TabbarItem Event

事件名参数

Tabbar Slot

名称说明
default-

TabbarItem Slot

名称说明
icon" :active="isActive-

样式变量

名称默认值
--pa-tabbar-height48px
--pa-tabbar-background-color#fff