组件 / 基础 / cu-tag 标签

cu-tag

标签用简短文字标记分类、状态或属性,可带图标与关闭按钮。

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-tag />

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

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

02 / Platform

平台支持

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

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

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

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

03 / Demo

代码演示

01

实心

uvue
<cu-tag text="info" type="info" />
<cu-tag text="success" type="success" />
<cu-tag text="primary" type="primary" />
<cu-tag text="error" type="error" />
<cu-tag text="warning" type="warning" />
02

描边

uvue
<cu-tag text="info" type="info" :plain="true" />
<cu-tag text="success" type="success" :plain="true" />
<cu-tag text="primary" type="primary" :plain="true" />
<cu-tag text="error" type="error" :plain="true" />
<cu-tag text="warning" type="warning" :plain="true" />
03

浅底

uvue
<cu-tag text="info" type="info" :plain="true" :plainFill="true" />
<cu-tag text="success" type="success" :plain="true" :plainFill="true" />
<cu-tag text="primary" type="primary" :plain="true" :plainFill="true" />
<cu-tag text="error" type="error" :plain="true" :plainFill="true" />
<cu-tag text="warning" type="warning" :plain="true" :plainFill="true" />
04

尺寸

uvue
<cu-tag text="large" size="large" type="primary" />
<cu-tag text="medium" size="medium" type="primary" />
<cu-tag text="mini" size="mini" type="primary" />
05

形状

uvue
<cu-tag text="square" shape="square" type="success" />
<cu-tag text="circle" shape="circle" type="success" />
06

可关闭

uvue
<cu-tag text="closable" type="error" :closable="true" name="t-closable" @close="onClose" />
<cu-tag text="自定义 closeColor" type="primary" :closable="true" closeColor="#1d7d32" />
07

自定义色

uvue
<cu-tag text="bgColor" bgColor="#f37b1d" />
<cu-tag text="color+border" color="#ffffff" bgColor="#39b54a" borderColor="#1d7d32" />
08

图标

uvue
<cu-tag text="带 icon" type="primary" icon="cuIcon-edit" />
09

禁用 / 隐藏

uvue
<cu-tag text="disabled" type="warning" :disabled="true" />
<cu-tag text="不该出现" type="error" :show="false" />
10

非法取值

uvue
<cu-tag text="type=green" type="green" />
<cu-tag text="默认(不传 type)" />
11

点击

uvue
<cu-tag text="点我" type="success" name="tag-click" @click="onTagClick" />
<cu-tag text="disabled 也发" type="warning" :disabled="true" name="tag-disabled" @click="onTagClick" />
<cu-tag text="× 只发 close" type="primary" :closable="true" name="tag-both" @click="onTagClick" @close="onCloseBoth" />
12

取值与事件

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

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
外观与状态
show是否显示Booleantrue
typeinfo / success / primary / error / warning 五档配色String'primary'
sizelarge / medium / mini 三档String'medium'
shapesquare / circleString'square'
plain镂空档:只描边,文字取主题色Booleanfalse
plainFill镂空再填浅色底;只在 plain 为真时生效Booleanfalse
颜色
bgColor自定义底色String''
color自定义文字色String''
borderColor自定义描边色String''
内容
text标签文字String''
icon左侧图标名,取 cu-icon 白名单String''
关闭
closable显示关闭按钮Booleanfalse
closeColor关闭按钮的背景色String'#C6C7CB'
name点击与关闭事件载荷里的标识String''
交互与样式
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
disabled禁用档;本仓未消费,传了不生效Booleanfalse
url不产生跳转,请在 @click 里自行跳转String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@click点击标签时触发,回传 nameHandler-各端一致
@close点击关闭按钮时触发,回传 nameHandler-各端一致

slots

slot说明
icon自定义左侧图标区;不填时按 icon 属性渲染
05 / Notes

注意事项

关闭是受控的 :点关闭只派发 close,标签不会自己消失;由外层改 show 收起。