Skip to content

Tag 标签

预览
01:38

组件名:rice-tag

用于标记关键词和概括主要内容。

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5

标签类型

支持 primary success warning error default 五种类型,默认为 default。通过 type 属性进行定义。

html
<rice-tag type="primary" text="主要" />
<rice-tag type="success" text="成功" />
<rice-tag type="warning" text="警告" />
<rice-tag type="error" text="错误" />
<rice-tag text="标签" />

朴素带浅色背景标签

通过 plain-fill 属性可以将标签设置为朴素标签

html
<rice-tag plain-fill type="primary" text="主要" />
<rice-tag plain-fill type="success" text="成功" />
<rice-tag plain-fill type="warning" text="警告" />
<rice-tag plain-fill type="error" text="错误" />

朴素标签

通过 plain 属性可以设置为朴素标签,此时文字的颜色为标签的颜色,标签的背景色为透明。

html
<rice-tag plain type="primary" text="主要" />
<rice-tag plain type="success" text="警告" />
<rice-tag plain type="warning" text="成功" />
<rice-tag plain type="error" text="错误" />

自定义颜色

通过 color 属性可以自定义标签的颜色,支持渐变色

html
<rice-tag color="#8b60ef" text="紫色" />
<rice-tag color="#8b60ef" plain-fill text="紫色" />
<rice-tag color="#8b60ef" plain text="紫色" />
<rice-tag color="linear-gradient(to right, rgb(255, 140, 8), rgb(238, 10, 36))" text="渐变" text-color="#fff" />

带图标

通过 icon 属性可以设置标签的图标。

html
<rice-tag icon="plus" type="primary" text="标签" />
<rice-tag icon="share" type="primary" text="标签" plain-fill />

可关闭标签

通过 closeable 属性可以设置标签为可关闭的,关闭标签时会触发 close 事件,在 close 事件中可以执行隐藏标签的逻辑。

html
<rice-tag closeable type="primary" :show="show1" text="标签" @click="onClick" @close="show1=false" />
<rice-tag closeable type="success" :show="show2" text="标签" @click="onClick" @close="show2=false" />

<script setup>
  
const show1 = ref(true)
const show2 = ref(true)

const onClick = () => {
  uni.showToast({
    title: '点击了标签',
    icon: 'none'
  })
}
</script>

样式风格

html
<rice-tag :round="false" type="primary" text="标签" />
<rice-tag mark type="success" text="标签" />

标签尺寸

通过 size 属性可以设置标签的尺寸大小,可选largesmall

html
<rice-tag size="small" type="primary" text="标签" />
<rice-tag type="primary" text="标签" />
<rice-tag size="large" type="primary" text="标签" />

API

Props

属性名类型说明默认值
typeString类型,可选值:primary、success、warning、error-
sizeString尺寸 可选值:large、small-
colorString背景颜色-
textString文字-
iconString图标名称,等同于Icon的name值-
text-colorString文字颜色-
text-sizeString|Number文字大小-
showBoolean是否显示-
plainBoolean是否为朴素按钮-
plain-fillBoolean是否为带背景颜色的朴素按钮-
roundBoolean是否圆角-
markBoolean是否为标记样式(半圆角)-
closeableBoolean是否可关闭-
custom-styleObject自定义样式-

Event

事件名说明回调参数
click点击事件-
close关闭标签时触发,在该事件中可以执行隐藏标签的逻辑。-

类型定义

组件导出如下类型

ts
//组件类型
const tagRef=ref<RiceTagComponentPublicInstance|null>(null)