Skip to content
在新窗口打开实时预览

Text 文本 ​

集成了文本类在项目中的常用功能:价格、手机号/姓名脱敏、日期格式化、超链接与拨打电话,几乎涵盖大部分文本场景。

平台兼容性 ​

H5App微信小程序支付宝小程序
√√√√

基础用法 ​

vue
<snake-text text="普通文本" />
<snake-text :text="1288" mode="price" />

模式与格式化 ​

vue
<!-- 手机号脱敏:138****8000 -->
<snake-text text="13800138000" mode="phone" format="encrypt" />
<!-- 姓名脱敏:张*丰 -->
<snake-text text="张三丰" mode="name" format="encrypt" />
<!-- 日期格式化 -->
<snake-text :text="timestamp" mode="date" format="yyyy-mm-dd" />
<!-- 超链接 -->
<snake-text text="打开链接" mode="link" href="https://example.com" />
<!-- 点击拨号 -->
<snake-text text="13800138000" mode="phone" call />

脱敏和日期格式化仅用于展示,不会修改原始值;需要提交或计算时仍应使用业务数据源。

API ​

Props ​

参数说明类型默认值
type主题颜色primary | warning | success | info | error | main | content | tips | light''
show是否显示文本booleantrue
text显示的值string | number''
prefixIcon / suffixIcon前置/后置图标string''
mode文本处理模式text | price | phone | name | date | linktext
hrefmode 为 link 时的链接地址string''
format格式化规则,encrypt 或函数string | function''
callmode 为 phone 时点击是否拨打电话booleanfalse
openType小程序打开方式string''
bold是否粗体booleanfalse
block是否块状显示booleanfalse
lines显示行数,超出显示省略号string | number''
color文本颜色string--snake-color-text
size字体大小string | number28
iconStyle / textStyle图标/文字样式object | array | string默认图标样式 / {}
decoration文字装饰none | underline | line-throughnone
margin外边距object | string | number0
lineHeight行高string | number''
align对齐方式left | center | rightleft
wordWrap换行方式break-word | normal | anywherenormal
customClass / customStyle自定义类名和样式string | object | array''

Events ​

事件名触发时机参数
click点击文本-
getuserinfo / contact / getphonenumber / error / launchapp / opensettingopenType 对应原生事件event.detail

Slots ​

名称说明
default替换默认显示内容

主题变量 ​

变量名说明
--snake-color-text默认文字及 main 颜色
--snake-color-text-secondarycontent 及图标颜色
--snake-color-text-mutedtips 颜色
--snake-color-text-lightlight 颜色
--snake-color-primaryprimary 颜色
--snake-color-successsuccess 颜色
--snake-color-warningwarning 颜色
--snake-color-errorerror 颜色
--snake-color-infoinfo 颜色

为 uni-app 商城与 CMS 场景设计