组件 / 反馈 / cu-alert 警告条

cu-alert

警告条在内容区里显示一条带色的提示框,用于说明风险或引导操作。

01 / Install

引入组件

整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。

install
# 1  整目录放进工程(easycom 自动解析)
your-project/
└── uni_modules/
    └── colorui-x/

# 2  App.uvue 全局引入主题层(一次)
@import 'uni_modules/colorui-x/theme/base.css';
@import 'uni_modules/colorui-x/theme/layout.css';
@import 'uni_modules/colorui-x/theme/color.scss';  // 颜色工具类(.bg-* / .text-*)

# 3  页面里直接用,不写 import(只编译用到的组件)
<cu-alert />

# 4  单个组件也可以显式引入(可选,不用 easycom 时)
import CuAlert from '@/uni_modules/colorui-x/components/cu-alert/cu-alert.uvue'

组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。

02 / Platform

平台支持

AndroidiOSHarmonyOSWeb(H5)微信小程序支付宝小程序
√ — — √ — —

Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。

Web 列只表示已编出可运行的预览产物,非真机渲染。

其余三端没有任何实测证据,不作支持承诺。

03 / Demo

代码演示

01

默认

uvue
<cu-alert title="这是一条默认档提示" />
02

类型

uvue
<cu-alert title="primary" type="primary" effect="light" />
<cu-alert title="success" type="success" effect="light" />
<cu-alert title="warning" type="warning" effect="light" />
<cu-alert title="error" type="error" effect="light" />
<cu-alert title="info" type="info" effect="light" />
03

类型 / 深底

uvue
<cu-alert title="primary dark" type="primary" effect="dark" />
<cu-alert title="success dark" type="success" effect="dark" />
<cu-alert title="warning dark" type="warning" effect="dark" />
<cu-alert title="error dark" type="error" effect="dark" />
<cu-alert title="info dark" type="info" effect="dark" />
04

描述 / 居中

uvue
<cu-alert title="带辅助文字" description="辅助文字颜色比标题浅一档、字号同由 fontSize 决定。" />
<cu-alert title="居中排版" description="center 为真时标题与辅助文字都居中。" :center="true" />
05

图标

uvue
<cu-alert title="success 图标" type="success" :showIcon="true" />
<cu-alert title="info 图标(dark)" type="info" effect="dark" :showIcon="true" />
06

字号

uvue
<cu-alert title="fontSize 12" :fontSize="12" />
<cu-alert title="fontSize 14(默认)" :fontSize="14" />
<cu-alert title="fontSize 18" type="error" effect="dark" :fontSize="18" />
07

空值与超长

uvue
<cu-alert type="info" />
<cu-alert title="这是一条用于观察提示条换行的超长标题,超长标题继续重复以撑满整行并触发换行" description="超长辅助文字:重复第三轮以观察关闭图标是否压住文字、内容区右内距是否如实留出、以及文字会不会被容器裁切。" type="warning" :closable="true" @click="onAlertClick" />
08

可关闭

uvue
<cu-alert v-if="closableMounted" title="可关闭:点右侧叉号" :closable="true" type="error" />
<cu-alert v-if="closableMounted" title="可关闭 + 图标 + 居中" :closable="true" :showIcon="true" :center="true" type="success" description="关闭按钮是 position: absolute 的浮层,App 端绝对定位未实测 ⇒ 真机验证项。" />
09

自定义类 / 点击

uvue
<cu-alert title="customClass 大圆角" customClass="custom-class" @click="onAlertClick" />
10

取值与事件

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
内容
title标题文字,加粗一行;空串不渲染String''
description辅助说明文字;空串不渲染String''
外观
typesuccess / warning / info / error / primary,决定底色与左侧图标String'warning'
effectlight 浅底深字 / dark 实底白字String'light'
showIcontrue ⇒ 左侧显示随 type 变化的图标Booleanfalse
centertrue ⇒ 标题与说明居中,默认靠左Booleanfalse
fontSize标题与说明的字号,px 契约值;运行时 ×2 换算成 rpxNumber14
交互与样式
closabletrue ⇒ 右侧显示关闭按钮,点击后整块不再渲染,且不抛事件Booleanfalse
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
url不产生跳转,请在 click 里自行跳转String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@click点击提示框主体时触发,无载荷;点右侧关闭按钮不触发Handler-各端一致

slots

slot说明
(默认)自定义提示内容;不填时按 title 与 description 渲染两行文字
05 / Notes

注意事项

关掉就回不来 :点关闭只把组件内部一个可见开关置假,既不发事件也没有受控入口;一旦关掉,想再显示只能让页面重新挂载它。