Skip to content

Text 文本

文本组件,用于展示文本信息。

组件类型

基本用法

通过 text 传入文本内容。

html
<wd-text :text="text"></wd-text>
ts
const text = ref('芦叶满汀洲,寒沙带浅流。二十年重过南楼。')

设置主题

通过 type 设置主题色,支持 primaryerrorsuccesswarningdefault

html
<wd-text type="primary" text="主色"></wd-text>
<wd-text type="error" text="错误"></wd-text>
<wd-text type="success" text="成功"></wd-text>
<wd-text type="warning" text="警告"></wd-text>
<wd-text text="默认"></wd-text>

模式

通过 mode 对文本做格式化处理,支持 textdatephonenameprice

html
<wd-text text="18888888888" mode="phone"></wd-text>
<wd-text text="王三" mode="name"></wd-text>
<wd-text text="1719976636911" mode="date"></wd-text>

金额

设置 mode="price" 可以展示金额格式化文本。

html
<wd-text text="16354.156" mode="price" type="success" decoration="line-through" prefix="¥" />

组件样式

自定义字体颜色

通过 color 设置文字颜色。

html
<wd-text :text="text" color="#36B8C2"></wd-text>

是否粗体

设置 bold 开启粗体。

html
<wd-text :text="text" bold></wd-text>

字体大小

通过 size 设置字体大小。

html
<wd-text :text="text" size="16px"></wd-text>

lines

设置 lines 限制显示行数,超出后显示省略号。

html
<wd-text :text="text" :lines="2" size="16px"></wd-text>

lineHeight

通过 lineHeight 设置行高。

html
<wd-text :text="text" :lines="2" lineHeight="20px"></wd-text>

文字装饰

通过 decoration 设置文字装饰线。

html
<wd-text :text="text" type="warning" decoration="underline" />

特殊样式

脱敏

设置 format 后,在 modephonename 时会进行脱敏展示。

html
<wd-text text="张长三" mode="name" :format="true"></wd-text>
<wd-text text="18888888888" mode="phone" :format="true"></wd-text>

前后插槽

通过 prefixsuffix 属性或同名插槽扩展前后内容。

html
<wd-text text="12345678901" mode="phone" format type="primary" prefix="Prefix" suffix="Suffix" />

<wd-text text="12345678901" mode="phone" format type="primary">
  <template #prefix>
    <text>Prefix</text>
  </template>
  <template #suffix>Suffix</template>
</wd-text>

Attributes

参数说明类型默认值
type主题类型,可选值为 defaultprimarysuccesswarningerrorTextTypedefault
text文本内容`stringnumber`
size字体大小string''
mode文本处理模式,可选值为 textdatephonenamepriceTextModetext
decoration文本装饰,可选值为 noneunderlineline-throughoverlineTextDecorationnone
callmode="phone" 时点击文本是否拨号booleanfalse
bold是否粗体booleanfalse
format是否脱敏,仅在 modephonename 时生效booleanfalse
color文本颜色string''
prefix前缀内容string-
suffix后缀内容string-
lines展示行数,超出后显示省略号number-
line-height文本行高string''
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

Events

事件名称说明参数
click点击文本时触发Event

Slots

名称说明
prefix前缀内容
suffix后缀内容

外部样式类

类名说明
custom-class根节点样式类
custom-style根节点内联样式

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-text-font-size$typography-body-size-main默认文字字号
--wot-text-line-height$typography-body-line--height-size-main默认文字行高
--wot-text-primary-color$primary-6主色文字颜色
--wot-text-success-color$success-main成功文字颜色
--wot-text-error-color$danger-main错误文字颜色
--wot-text-warning-color$warning-main警告文字颜色
--wot-text-default-color$text-auxiliary默认文字颜色

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.