Skip to content

nax-alert

当前版本:0.1.4

警告提示条(页面内常驻提示)。提供常用能力。

安装

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

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

代码示例

用法
uvue
<nax-alert title="温馨提示" description="请先完成实名认证后再操作。"></nax-alert>

<nax-alert type="success" title="提交成功" description="我们已收到你的申请。"></nax-alert>

<nax-alert
  type="error"
  closable
  :show="alertShow"
  title="账号异常"
  description="检测到异地登录,请修改密码。"
  @close="onClose"
  @update:show="onShowChange"
></nax-alert>
基础
uvue
<nax-alert
	title="温馨提示"
	description="请先完成实名认证后再进行提现操作。"
></nax-alert>
类型 type
uvue
<nax-alert type="primary" title="主色提示" description="这是 primary 类型。"></nax-alert>
<nax-alert type="info" title="信息提示" description="这是 info 类型。"></nax-alert>
<nax-alert type="success" title="成功提示" description="操作已成功完成。"></nax-alert>
<nax-alert type="warning" title="警告提示" description="请注意相关风险。"></nax-alert>
<nax-alert type="error" title="错误提示" description="提交失败,请稍后重试。"></nax-alert>
实心 variant=solid
uvue
<nax-alert type="info" variant="solid" title="信息" description="实心填充样式。"></nax-alert>
<nax-alert type="success" variant="solid" title="成功" description="实心填充样式。"></nax-alert>
<nax-alert type="warning" variant="solid" title="警告" description="实心填充样式。"></nax-alert>
<nax-alert type="error" variant="solid" title="错误" description="实心填充样式。"></nax-alert>
仅标题 / 仅描述
uvue
<nax-alert type="info" title="只有标题"></nax-alert>
<nax-alert type="warning" description="只有描述文字,没有标题。"></nax-alert>
无图标 / 自定义图标
uvue
<nax-alert :show-icon="false" type="info" title="不显示图标" description="show-icon=false"></nax-alert>
<nax-alert icon="star" type="primary" title="自定义图标" description="icon=star"></nax-alert>
居中 center
uvue
<nax-alert
	center
	type="success"
	title="居中展示"
	description="标题与描述水平居中。"
></nax-alert>
可关闭 closable
uvue
<nax-alert
	v-if="showCloseA"
	closable
	type="error"
	title="账号异常"
	description="检测到异地登录,建议立即修改密码。"
	@close="onCloseA"
></nax-alert>

<nax-alert
	closable
	:show="showCloseB"
	type="warning"
	title="受控显示"
	description="使用 show + update:show 控制。"
	@close="onCloseB"
	@update:show="onShowB"
></nax-alert>

<nax-button size="sm" label="重置关闭示例" @click="resetClose"></nax-button>
uts
const showCloseA = ref(true)
const showCloseB = ref(true)

function onCloseA() {
	showCloseA.value = false
}

function onCloseB() {
	// 非受控关闭:组件已自行隐藏
}

function onShowB(v: boolean) {
	showCloseB.value = v
}

function resetClose() {
	showCloseA.value = true
	showCloseB.value = true
}
默认插槽
uvue
<nax-alert type="info" title="自定义描述">
	<text>描述可用默认插槽自定义,例如补充链接说明文案。</text>
</nax-alert>

主题

通过 CSS 变量覆盖:

Token用途
--nax-color-error错误色
--nax-color-error-secondary错误色浅底
--nax-color-info信息色
--nax-color-info-secondary信息色浅底
--nax-color-primary主题主色
--nax-color-primary-secondary主题主色浅底
--nax-color-success成功色
--nax-color-success-secondary成功色浅底
--nax-color-text-inverse反白文字色
--nax-color-text-secondary次要文字色
--nax-color-warning警告色
--nax-color-warning-deep警告色(加深)
--nax-color-warning-secondary警告色浅底

Props

属性类型默认值说明
typestring'warning'primary 主要 | info 信息 | success 成功 | warning 警告 | error 错误(兼容 danger);默认 warning
variantstring'light'light 浅色 | solid 实心(兼容 effect 的 light/dark);默认 light
effectstring''兼容别名:light(对应 light)/ dark(对应 solid
titlestring''标题
descriptionstring''描述;也可用默认插槽
closablebooleanfalse是否可关闭
showIconbooleantrue是否显示左侧图标,默认 true
iconstring''自定义 nax-icon 名;空则按 type 映射
centerbooleanfalse内容是否水平居中
showbooleantrue是否显示;配合 update:show
customClassstring''根节点扩展 class

Events

事件说明
click点击主体
close关闭
update:show显示状态变化

Slots

插槽说明
default自定义描述内容
title自定义标题
icon自定义左侧图标