Skip to content

Badge

基础用法

html

<view class="demo-badge">
  <pa-badge content="5">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="10">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="new">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge dot>
    <view class="demo-badge-block"></view>
  </pa-badge>
</view>

最大值

html

<view class="demo-badge">
  <pa-badge content="999" :max="9">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="999" :max="20">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="999" :max="99">
    <view class="demo-badge-block"></view>
  </pa-badge>
</view>

自定义颜色

html

<view class="demo-badge">
  <pa-badge content="5" color="#1989fa">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="10" color="#1989fa">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="new" color="#1989fa">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="new" color="#1989fa" dot>
    <view class="demo-badge-block"></view>
  </pa-badge>
</view>

自定义内容

html

<view class="demo-badge">
  <pa-badge>
    <view class="demo-badge-block"></view>
    <template #content>
      <pa-icon name="success" color="#fff" />
    </template>
  </pa-badge>
  <pa-badge>
    <view class="demo-badge-block"></view>
    <template #content>
      <pa-icon name="favor" color="#fff" />
    </template>
  </pa-badge>
</view>

自定义位置

html

<view class="demo-badge">
  <pa-badge content="99" :offset="[-10, -10]">
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="99" :offset="[80, 0]">
    <view class="demo-badge-block"></view>
  </pa-badge>
</view>

边框

html

<view class="demo-badge">
  <pa-badge content="6" border>
    <view class="demo-badge-block"></view>
  </pa-badge>
  <pa-badge content="99" border border-color="#000">
    <view class="demo-badge-block"></view>
  </pa-badge>
</view>

独立展示

html

<view class="demo-badge">
  <pa-badge content="9" />
  <pa-badge content="99" />
</view>

Badge Props

参数说明类型默认值
content徽标内容number | string-
color徽标背景颜色CSSProperties['color']var(--pa-color-danger)
dot是否展示为小点boolean-
maxmax 最大值,超过最大值会显示 {max}+,仅当 content 为数字时有效number-
offset设置徽标的偏移量,数组的两项分别对应水平和垂直方向的偏移量,默认单位为rpxArray<number|string>() => [0, 0]
showZero当 content 为数字 0 或字符串 '0' 时,是否展示徽标boolean-
show是否显示booleantrue
border是否显示边框boolean-
borderColor边框颜色CSSProperties['color']-

Badge Event

事件名参数

Badge Slot

名称说明
default-
content-

样式变量

名称默认值
--pa-badge-font-size11px
--pa-badge-font-size11px
--pa-badge-padding2px 5px
--pa-badge-colorvar(--pa-color-danger)
--pa-badge-border-width1px
--pa-badge-border-color#fff