Skip to content

nax-empty

当前版本:0.1.3

空状态占位。用于列表无数据、搜索无结果、加载失败等场景。

安装

easycom 自动生效,页面直接使用 <nax-empty /> 即可。

建议同时安装主题包 uni_modules/nax-ui-theme 并在 App.uvue 引入主题变量,详见 主题接入

代码示例

用法
uvue
<!-- 基础 -->
<nax-empty></nax-empty>

<!-- 自定义文案 + 操作 -->
<nax-empty title="暂无订单" description="去逛逛,下单后会出现在这里">
  <template #action>
    <nax-button type="primary" size="sm" label="去首页" @click="goHome"></nax-button>
  </template>
</nax-empty>

<!-- 图标语义 -->
<nax-empty icon="file-off" description="暂无相关文件"></nax-empty>
<nax-empty icon="message-off" description="消息箱是空的"></nax-empty>

<!-- 自定义图片 -->
<nax-empty image="/static/empty.png" description="网络异常"></nax-empty>
基础
uvue
<nax-empty></nax-empty>
标题 + 描述
uvue
<nax-empty icon="notes-off" title="暂无订单" description="下单后,订单会出现在这里"></nax-empty>
图标语义
uvue
<nax-empty icon="file-off" description="暂无相关文件"></nax-empty>
<nax-empty icon="notes-off" description="暂无列表"></nax-empty>
<nax-empty icon="database-off" description="暂无数据"></nax-empty>
<nax-empty icon="message-off" description="消息箱是空的"></nax-empty>
操作按钮
uvue
<nax-empty icon="notes-off" title="列表为空" description="试着新建一条数据吧">
	<template #action>
		<nax-button type="primary" size="sm" label="新建" @click="onCreate"></nax-button>
	</template>
</nax-empty>
uts
const lastEvent = ref('无')

function onCreate() {
	lastEvent.value = '新建'
}
多个操作

action 插槽配合 nax-space 排列多个按钮。

uvue
<nax-empty icon="search" description="换个关键词试试">
	<template #action>
		<nax-space size="sm">
			<nax-space-item>
				<nax-button size="sm" label="清空筛选" @click="onClear"></nax-button>
			</nax-space-item>
			<nax-space-item>
				<nax-button type="primary" size="sm" label="重新搜索" @click="onSearch"></nax-button>
			</nax-space-item>
		</nax-space>
	</template>
</nax-empty>
uts
function onClear() {
	// 清空筛选
}

function onSearch() {
	// 重新搜索
}
尺寸 image-size
uvue
<nax-empty image-size="sm" description="小号 sm"></nax-empty>
<nax-empty image-size="md" description="中号 md(默认档)"></nax-empty>
隐藏插图
uvue
<nax-empty :show-image="false" description="仅文案的空状态"></nax-empty>
自定义插图槽
uvue
<nax-empty description="使用 #image 自定义">
	<template #image>
		<nax-icon name="star" size="40" color="#f0a020"></nax-icon>
	</template>
	<template #action>
		<nax-button size="sm" type="warning" label="去收藏" @click="onStar"></nax-button>
	</template>
</nax-empty>
uts
function onStar() {
	// 去收藏
}

主题

通过 CSS 变量覆盖:

Token用途
--nax-color-bg-secondary次级背景色
--nax-color-text主文字色
--nax-color-text-secondary次要文字色

Props

属性类型默认值说明
showbooleantrue是否显示,默认 true
titlestring''主标题(可选)
descriptionstring'暂无数据'描述文案,默认「暂无数据」
imagestring''插图地址;有值时优先于 icon
imageSizestring'120'sm 小 | md 中 | lg 大 或数字(px);默认 120
imageModestring'aspectFit'图片 mode,默认 aspectFit
iconstring''无图时的 nax-icon 名;空则 database-off(暂无数据)
iconSizestring'48'sm 小 | md 中 | lg 大 或数字(px);默认 48
iconColorstring''图标颜色
showImagebooleantrue是否展示插图区,默认 true
customClassstring''根节点扩展 class

Slots

插槽说明
image自定义插图
title自定义标题
description自定义描述
action操作区(按钮等)
default额外内容