Yt-UI
首页
快速开始
组件文档
首页
快速开始
组件文档
  • 表单组件

    • 输入框 Input
    • 多行输入框 Textarea
    • 开关 Switch
    • 多选框组 CheckboxGroup
    • 单选框组 RadioGroup
    • 滑块 Slider
    • 选择器 Picker
    • 日历 Calendar
    • 表单 Form
  • 展示组件

    • 头像 Avatar
    • 徽标 Badge
    • 卡片 Card
    • 标签 Tag
    • 步骤条 Steps
    • 结果页 Result
    • 空状态 Empty
    • 虚拟列表 VirtualList
  • 交互组件

    • 按钮 Button
    • 悬浮按钮 FAB
    • 图标 Icon
    • 搜索 Search
    • 分段器 Segment
    • 轮播 Swiper
    • 指示点 Dots
  • 反馈组件

    • 加载 Loading
    • 弹窗 Popup
    • 遮罩层 Overlay
    • 通告栏 NoticeBar
  • 导航组件

    • 标签栏 Tabbar
    • 顶部标签栏 TopTabbar
    • 折叠面板 Collapse
    • 课程表 Schedule
  • 布局组件

    • 分割线 Divider
    • 链接 Line
    • 可移动视图 MovableView

yt-empty 空状态组件

属性

属性名类型默认值说明
type'fail' | 'empty' | 'done' | 'champion' | 'error''empty'空状态类型
sizenumber24图标大小

类型说明

类型对应图标使用场景
failFail操作失败
emptyEmpty数据为空
doneDone操作完成
championChampion优胜/冠军状态
errorError错误状态

示例

基本空状态

<yt-empty />

<yt-empty type="empty" />

不同状态类型

<yt-empty type="fail" />

<yt-empty type="done" />

<yt-empty type="champion" />

<yt-empty type="error" />

自定义尺寸

<yt-empty :size="32" />

<yt-empty type="fail" :size="40" />

<yt-empty type="done" :size="48" />

<yt-empty type="champion" :size="60" />

数据为空页面

<template>
  <view
    v-if="list.length === 0"
    class="empty-page"
  >
    <yt-empty
      type="empty"
      :size="80"
    />
    <text class="empty-text">暂无数据</text>
    <yt-button @click="refresh">刷新</yt-button>
  </view>
  <view v-else>
    <!-- 正常内容 -->
  </view>
</template>

操作失败状态

<template>
  <view
    v-if="isError"
    class="error-state"
  >
    <yt-empty
      type="fail"
      :size="60"
    />
    <text class="error-text">加载失败,请重试</text>
    <yt-button @click="retry">重试</yt-button>
  </view>
</template>

完成状态

<template>
  <view
    v-if="isComplete"
    class="complete-state"
  >
    <yt-empty
      type="done"
      :size="72"
    />
    <text class="complete-text">任务已完成!</text>
  </view>
</template>

优胜/冠军状态

<template>
  <view
    v-if="isWinner"
    class="winner-state"
  >
    <yt-empty
      type="champion"
      :size="100"
    />
    <text class="winner-text">恭喜您获得第一名!</text>
  </view>
</template>

错误状态

<template>
  <view
    v-if="hasError"
    class="error-state"
  >
    <yt-empty
      type="error"
      :size="64"
    />
    <text class="error-text">系统错误,请联系管理员</text>
  </view>
</template>

响应式空状态

<script setup>
  import { computed } from 'vue'

  const props = defineProps({
    state: {
      type: String,
      default: 'empty',
      validator: value => ['empty', 'loading', 'error', 'success'].includes(value)
    }
  })

  const emptyType = computed(() => {
    switch (props.state) {
      case 'error':
        return 'error'
      case 'success':
        return 'done'
      default:
        return 'empty'
    }
  })

  const emptySize = computed(() => {
    return window.innerWidth < 768 ? 60 : 80
  })
</script>

<template>
  <view
    v-if="state !== 'loading'"
    class="state-container"
  >
    <yt-empty
      :type="emptyType"
      :size="emptySize"
    />
    <text>{{ getStateText(state) }}</text>
  </view>
  <view v-else>
    <yt-loading />
  </view>
</template>

完整示例

<script setup>
  import { ref } from 'vue'

  const dataState = ref('empty') // 'empty' | 'success' | 'error' | 'fail'
  const emptySize = ref(80)

  function loadData() {
    dataState.value = 'loading'
    // 模拟数据加载
    setTimeout(() => {
      const result = Math.random()
      if (result > 0.7) {
        dataState.value = 'success'
      } else if (result > 0.3) {
        dataState.value = 'empty'
      } else {
        dataState.value = 'error'
      }
    }, 1000)
  }
</script>

<template>
  <view class="data-container">
    <view v-if="dataState === 'loading'">
      <yt-loading />
    </view>
    <view
      v-else-if="dataState === 'empty'"
      class="state-view"
    >
      <yt-empty
        type="empty"
        :size="emptySize"
      />
      <text>暂无数据</text>
      <yt-button @click="loadData">重新加载</yt-button>
    </view>
    <view
      v-else-if="dataState === 'success'"
      class="state-view"
    >
      <yt-empty
        type="done"
        :size="emptySize"
      />
      <text>数据加载成功!</text>
    </view>
    <view
      v-else-if="dataState === 'error'"
      class="state-view"
    >
      <yt-empty
        type="error"
        :size="emptySize"
      />
      <text>数据加载失败</text>
      <yt-button @click="loadData">重试</yt-button>
    </view>
  </view>
</template>
最近更新:: 2026/1/2 20:18
Contributors: CHEEMS
Prev
结果页 Result
Next
虚拟列表 VirtualList