Skip to content

xtf-empty

组件说明

xtf-empty 是空状态组件,用于在数据为空时展示占位提示。支持多种预设类型(默认/网络/搜索/消息/收藏/订单/通知/404/403/500)、自定义图片、图标、描述文字和操作按钮,适用于列表为空、加载失败和权限限制等场景。


基础用法

1. 默认空状态

通过 type 使用预设空状态:

vue
<template>
  <xtf-empty type="default" />
</template>

2. 不同预设类型

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 48rpx">
    <xtf-empty type="network" />
    <xtf-empty type="search" />
    <xtf-empty type="message" />
    <xtf-empty type="404" />
  </view>
</template>

3. 自定义内容

通过 titledescimage 自定义内容:

vue
<template>
  <xtf-empty title="暂无商品" desc="快去添加第一件商品吧!" image="/static/empty-product.png" />
</template>

4. 带操作按钮

通过 actionText 设置操作按钮文字:

vue
<template>
  <xtf-empty type="network" action-text="重新加载" @action="onReload" />
</template>

<script>
export default {
  methods: {
    onReload() {
      console.log('重新加载')
    }
  }
}
</script>

5. 自定义图片与操作插槽

vue
<template>
  <xtf-empty title="收藏为空">
    <template #image>
      <xtf-icon name="favorite" theme="danger" size="xl" variant="soft" padding="32rpx" round
    /></template>
    <template #action><xtf-button label="去浏览" @click="goBrowse" /></template>
  </xtf-empty>
</template>

<script>
export default {
  methods: {
    goBrowse() {
      uni.showToast({ title: '跳转浏览页', icon: 'none' })
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
typeString'default'预设类型:'default' / 'network' / 'search' / 'message' / 'favorite' / 'order' / 'notice' / '404' / '403' / '500'预设类型
imageString''自定义图片 URL自定义图片
titleString''标题文字标题
descString''描述文字描述
iconString''自定义图标名称图标
iconSizeString | Number'xl'图标大小图标大小
imageSizeString | Number''图片大小图片尺寸
themeString'primary'主题色主题
actionTextString''操作按钮文字操作按钮
compactBooleanfalse是否紧凑模式紧凑
floatBooleantrue是否浮动动画动画
customClassString''自定义类名样式覆盖
customStyleString | Object''自定义样式动态样式覆盖

事件

事件名称触发时机回调参数参数说明
action点击操作按钮时触发(event)事件对象
click点击操作按钮时触发(event)事件对象

插槽

插槽名称说明
image自定义图片区域
action自定义操作按钮区域

上方第五个示例同时展示了 imageaction 的实际插槽用法。


主题说明

  • 图标使用 xtf-icon 组件
  • 标题使用 xtf-text 组件
  • 描述使用 xtf-text 组件
  • 操作按钮使用 xtf-button 组件
  • 支持浮动动画效果

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖相关 CSS 变量。

MIT Licensed