Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

Text 文本

此组件集成了文本类在项目中的常用功能,包括状态,拨打电话,格式化日期,*替换,超链接...等功能。 您大可不必在使用特殊文本时自己定义,text组件几乎涵盖您能使用的大部分场景。

注意:

由于在nvue下,u-text名称被uni-app官方占用,在nvue页面中请使用up-text名称,在vue页面中使用up-text或者up-text均可。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

  • 通过text参数设置文本内容。推荐您使用:text='value'的形式
html
<up-text text="我用十年青春,赴你最后之约"></up-text>

设置主题

  • 通过type参数设置文本主题,我们提供了五类属性。
  • primary error success warning info
html
<up-text type="primary" text="主色"></up-text>
<up-text type="error"   text="错误"></up-text>
<up-text type="success" text="成功"></up-text>
<up-text type="warning" text="警告"></up-text>
<up-text type="info"    text="信息"></up-text>

拨打电话

  • 通过将mode属性设置为phone即可调用拨打电话,提供加密值encrypt
  • 除此之外还有格式化日期,姓名脱敏,超链接,千分位金额等属性,将在以下实例中展示
html
<up-text mode="phone" text="15019479320"></up-text>

日期格式化

html
<up-text mode="date" text="1612959739"></up-text>

姓名脱敏

html
<up-text mode="name" text="张三三" format="encrypt"></up-text>

超链接

添加href指定链接地址

html
<up-text mode="link" text="Go to uView docs" href="https://www.uviewui.com" ></up-text>

显示金额

html
<up-text mode="price" text="728732.32"></up-text>

前后图标

添加prefixIcon,suffixIcon指定图标和位置,iconStyle设置图标大小

html
<up-text prefixIcon="baidu" iconStyle="font-size: 19px" text="百度一下,你就知道"></up-text>
<up-text suffixIcon="arrow-leftward" iconStyle="font-size: 18px" text="查看更多"></up-text>

超出隐藏

内置了文字超出隐藏样式,设置lines属性表明几行后隐藏

html
<up-text :lines="2" text="关于uView的取名来由,首字母u来自于uni-app首字母,
uni-app是基Vuejs,Vue和View(延伸为UI、视图之意)同音,同时view组件uni-app中
最础最重要的组件,故取名uView,表达源于uni-app和Vue之意,同时在此也对它示感谢。"></up-text>

小程序开放能力

针对小程序开放能力,我们提供了分享,请在小程序环境下使用

html
<up-text text="分享到微信" openType="share" type="success" @click="clickHandler"></up-text>
<script>
	export default {
		onLoad() {},
		methods: {
			clickHandler() {
				// #ifndef MP-WEIXIN
				uni.$u.toast('请在微信小程序内查看效果')
				// #endif
			}
		},
	}
</script>

此页面源代码地址

页面源码地址


 github  gitee

API

List Props

参数说明类型默认值可选值
type主题颜色String--
show是否显示Booleantruefalse
text显示的值String | Number--
prefixIcon前置图标String--
suffixIcon后置图标String--
mode文本处理的匹配模式text-普通文本,price-价格,phone-手机号,name-姓名,date-日期,link-超链接String-
hrefmode=link下,配置的链接String--
format格式化规则String | Function--
callmode=phone时,点击文本是否拨打电话Booleanfalsetrue
openType小程序的打开方式String--
bold是否粗体,默认normalBooleanfalsetrue
block是否块状Booleanfalsetrue
lines文本显示的行数,如果设置,超出此行数,将会显示省略号String | Number--
color文本颜色String#303133-
size字体大小String | Number15-
iconStyle图标的样式Object | String15px-
decoration文字装饰,下划线,中划线等Stringnoneunderline/line-through
margin外边距,对象、字符串,数值形式均可Object | Number | String--
lineHeight文本行高Number | String--
align文本对齐方式Stringleftcenter/right
wordWrap文字换行Stringnormalbreak-word/anywhere

List Events

事件名说明回调参数
click点击触发事件-

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发