17. 基础内容
于2023-06-25 14:44:16发布
45
icon
图标。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)
属性名 | 类型 | 默认值 | 说明 |
type | String | icon的类型,有效值:success, success_no_circle, info, warn, waiting, cancel, download, search, clear | |
size | Number | 23 | icon的大小,单位px |
color | Color | icon的颜色,同css的color |
例子
<icon type="success"/>
<icon type="success_no_circle"/>
<icon type="info"/>
<icon type="warn"/>
<icon type="waiting"/>
<icon type="cancel"/>
<icon type="download"/>
<icon type="search"/>
<icon type="clear"/>
<icon type="success" size="60" color="#000"/>
text
文本
属性名 | 类型 | 默认值 | 说明 | 最低版本 |
selectable | Boolean | false | 文本是否可选 | 1.1.0 |
space | String | false | 显示连续空格 | 1.4.0 |
decode | Boolean | false | 是否解码 | 1.4.0 |
space 有效值:
值 | 说明 |
ensp | 中文字符空格一半大小 |
emsp | 中文字符空格大小 |
nbsp | 根据字体设置的空格大小 |
下面对上面的属性做简单的介绍
selectable
文本是否可选,需要在真机上测试
space
<text>点我 哈哈哈哈哈</text>
如上,虽然代码上写了很多个空格,但是界面只显示一个空格
解决方法是给text一个space属性
<text space="nbsp">点我 哈哈哈哈哈</text>
decode
<text>点我 哈哈哈哈哈</text>
在html,我们可以使用 来代表空格,而在小程序中却行不通。decode就是为了解决这个问题而存在的。
<text decode>点我 哈哈哈哈哈</text>
Tips
1. decode可以解析的有 < > & '
2. text组件内只支持text嵌套
3. 除了文本节点以外的其他节点都无法长按选中
rich-text
rich-text是富文本标签,可以将字符串解析成对应标签,类似vue中 v-html功能;其利用nodes属性接收输入的html值,nodes可以接收以下两种类型值:标签字符串 和 对象数组。
例子
wxml
<rich-text nodes="{{html1}}"></rich-text>
<rich-text nodes="{{html2}}"></rich-text>
js
Page({
data: {
html1:`<h1>这里是h1标签,富文本会将元素当成HTML标签解析后输出--字符串格式</h1>`,
html2:[
{
// 1 div标签 name属性来指定
name:'h1',
// 2 标签上有哪些属性
attrs:{
// 标签上的属性 class style
class:'my_h1',
style:"color:red;"
},
// 2 子节点 children 要接收的数据类型和 nodes第二种渲染方式的数据类型一致
children:[
{
name:"p",
attrs:[],
// 放文本
children:[
{
type:"text",
text:"这里是h1标签,富文本会将元素当成HTML标签解析后输出--数组格式"
}
]
}
]
}
]
},
})
progress
进度条。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。
属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 |
percent | number | 否 | 百分比0~100 | 1.0.0 | |
show-info | boolean | false | 否 | 在进度条右侧显示百分比 | 1.0.0 |
border-radius | number/string | 0 | 否 | 圆角大小 | 2.3.1 |
font-size | number/string | 16 | 否 | 右侧百分比字体大小 | 2.3.1 |
stroke-width | number/string | 6 | 否 | 进度条线的宽度 | 1.0.0 |
color | string | #09BB07 | 否 | 进度条颜色(请使用activeColor) | 1.0.0 |
activeColor | string | #09BB07 | 否 | 已选择的进度条的颜色 | 1.0.0 |
backgroundColor | string | #EBEBEB | 否 | 未选择的进度条的颜色 | 1.0.0 |
active | boolean | false | 否 | 进度条从左往右的动画 | 1.0.0 |
active-mode | string | backwards | 否 | backwards: 动画从头播;forwards:动画从上次结束点接着播 | 1.7.0 |
duration | number | 30 | 否 | 进度增加1%所需毫秒数 | 2.8.2 |
bindactiveend | eventhandle | 否 | 动画完成事件 | 2.4.1 |
例子
<progress percent='20' />
<progress percent='30' show-info='true' />
<progress percent='40' show-info='true' stroke-width='30' />
<progress percent='50' show-info='true' active='true' />
<progress percent='60' show-info='true' active='true' backgroundColor='pink' />
<progress percent='90' show-info='true' active='true' activeColor='pink' />