【微信小程序】WXML-组件


前言

学习微信小程序的组件,参考官方DOC。
需要啥组件直接去官方DOC拿code就完事=)


一、常见组件

view

相当于HTML里的<div></div>

属性说明

属性类型默认值必填说明最低版本
hover-classstringnone指定按下去的样式类。当 hover-class=“none” 时,没有点击态效果1.0.0
hover-stop-propagationbooleanfalse指定是否阻止本节点的祖先节点出现点击态1.5.0
hover-start-timenumber50按住后多久出现点击态,单位毫秒1.0.0
hover-stay-timenumber400手指松开后点击态保留时间,单位毫秒1.0.0

注:
如果需要使用滚动视图,请使用 scroll-view

text

相当于HTML里的<span></span>

通用属性

属性类型默认值必填说明最低版本
selectablebooleanfalse文本是否可选 (已废弃)1.1.0
user-selectbooleanfalse文本是否可选,该属性会使文本节点显示为 inline-block2.12.1

Skyline 特有属性

属性类型默认值必填说明
overflowstringvisible文本溢出处理
max-linesnumber限制文本最大行数
  • overflow合法值及说明
合法值说明
clip修剪文本
fade淡出
ellipsis显示省略号
visible文本不截断

WebView 特有属性

属性类型默认值必填说明最低版本
spacestring显示连续空格1.4.0
decodebooleanfalse是否解码1.4.0
  • WebView合法值及说明
合法值说明
ensp中文字符空格一半大小
emsp中文字符空格大小
nbsp根据字体设置的空格大小

注:

  1. tip: decode可以解析的有   < > & '    
  2. tip: 各个操作系统的空格标准并不一致。
  3. tip:text 组件内只支持 text 嵌套。
  4. tip: 除了文本节点以外的其他节点都无法长按选中。
  5. bug: 基础库版本低于 2.1.0 时, text 组件内嵌的 text style 设置可能不会生效。

swiper

滑块视图容器。其中只可放置swiper-item组件,否则会导致未定义的行为。

  • 使用 worklet 函数需要开启开发者工具 “将 JS 编译成 ES5” 或 “编译 worklet 函数” 选项。

通用属性

属性类型默认值必填说明最低版本
indicator-dotsbooleanfalse是否显示面板指示点1.0.0
indicator-colorcolorrgba(0, 0, 0, .3)指示点颜色1.1.0
indicator-active-colorcolor#000000当前选中的指示点颜色1.1.0
autoplaybooleanfalse是否自动切换1.0.0
currentnumber0当前所在滑块的 index1.0.0
intervalnumber5000自动切换时间间隔1.0.0
durationnumber500滑动动画时长1.0.0
circularbooleanfalse是否采用衔接滑动1.0.0
verticalbooleanfalse滑动方向是否为纵向1.0.0
display-multiple-itemsnumber1同时显示的滑块数量1.9.0
previous-marginstring“0px”前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值1.9.0
next-marginstring“0px”后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值。skyline 于 3.5.1 版本支持1.9.0
easing-functionstring“default”指定 swiper 切换缓动动画类型2.6.5
bindchangeeventhandlecurrent 改变时会触发 change 事件,event.detail = {current, source}1.0.0
bindtransitioneventhandleswiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}。Skyline 仅支持非 worklet 的组件方法作为回调。2.4.3
bindanimationfinisheventhandle动画结束时会触发 animationfinish 事件,event.detail 同 bindchange。Skyline 仅支持非 worklet 的组件方法作为回调。1.9.0
  • easing-function合法值及说明
合法值说明
default默认缓动函数
linear线性动画
easeInCubic缓入动画
easeOutCubic缓出动画
easeInOutCubic缓入缓出动画

Skyline 特有属性

属性类型默认值必填说明最低版本
layout-typestringnormal渲染模式3.2.0
transformer-typestringscaleAndFadelayout-type 为 transformer 时指定动画类型3.2.0
indicator-typestringnormal指示点动画类型3.2.0
indicator-marginnumber10指示点四周边距3.2.0
indicator-spacingnumber4指示点间距3.2.0
indicator-radiusnumber4指示点圆角大小3.2.0
indicator-widthnumber8指示点宽度3.2.0
indicator-heightnumber8指示点高度3.2.0
indicator-alignmentArray./stringauto指示点的相对位置3.2.0
indicator-offsetArray.[0, 0]指示点位置的偏移量3.2.0
scroll-with-animationbooleantrue改变 current 时使用动画过渡2.29.0
cache-extentnumber0缓存区域大小,值为 1 表示提前渲染上下各一屏区域(swiper 容器大小)2.29.0
worklet:onscrollstartworklet滑动开始时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
worklet:onscrollupdateworklet滑动位置更新时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
worklet:onscrollendworklet滑动结束时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
  • layout-type合法值及说明
合法值说明
normal默认方式
stackLeft左向堆叠
stackRight右向堆叠
tinder滑动卡片
transformer过渡动画
  • transformer-type合法值及说明
合法值说明
scaleAndFade
accordion
threeD
zoomIn
zoomOut
deepthPage
  • indicator-type合法值及说明
合法值说明
normal
worm
wormThin
wormUnderground
wormThinUnderground
expand
jump
jumpWithOffset
scroll
scrollFixedCenter
slide
slideUnderground
scale
swap
swapYRotation
color

WebView 特有属性

属性类型默认值必填说明最低版本
snap-to-edgebooleanfalse当 swiper-item 的个数大于等于 2,关闭 circular 并且开启 previous-margin 或 next-margin 的时候,可以指定这个边距是否应用到第一个、最后一个元素2.12.1

注:

  1. layout-type 为 stackLeft stackRight 和 tinder 时仅支持 indicator-type=normal
  2. indicator-type 为 scrollFixedCenter swap swapYRotation 无法在循环模式 circular 下使用
  3. indicator-alignment 可指定为关键词 auto 或 长度为 2 的数组。
    • 横向滑动时 auto 相当于 bottomCenter [0, 1]
    • 纵向滑动时,auto 相当于 centerRight [1, 0]
    • 传入数组时,表示 x/y 轴的相对位置,取值范围 [-1, 1],底边中点为 [0, 1]
  4. indicator-offset 是长度为 2 的数组,表示指示点在 x/y 轴上的偏移量,单位 px。
  5. skyline 的 previous-margin、 display-multiple-items 和 vertical 属性与 webview 表现略有不同,当skyline 使用 next-margin 属性且其值大于 0 时,会将前述三个属性对齐 webview 实现。

progress

进度条。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。

通用属性

属性类型默认值必填说明最低版本
percentnumber百分比0~1001.0.0
show-infobooleanfalse在进度条右侧显示百分比1.0.0
border-radiusnumber/string\0圆角大小2.3.1
font-sizenumber/string16右侧百分比字体大小2.3.1
stroke-widthnumber/string6进度条线的宽度1.0.0
colorstring#09BB07进度条颜色(请使用activeColor)1.0.0
activeColorstring#09BB07已选择的进度条的颜色1.0.0
backgroundColorstring#EBEBEB未选择的进度条的颜色1.0.0
activebooleanfalse进度条从左往右的动画1.0.0
active-modestringbackwardsbackwards: 动画从头播;forwards:动画从上次结束点接着播1.7.0
durationnumber30进度增加1%所需毫秒数2.8.2
bindactiveendeventhandle动画完成事件2.4.1

button

按钮

通用属性

属性类型默认值必填说明最低版本
sizestringdefault按钮的大小1.0.0
typestringdefault按钮的样式类型1.0.0
plainbooleanfalse按钮是否镂空,背景色透明1.0.0
disabledbooleanfalse是否禁用1.0.0
loadingbooleanfalse名称前是否带 loading 图标1.0.0
form-typestring用于 form 组件,点击分别会触发 form 组件的 submit/reset 事件1.0.0
open-typestring微信开放能力1.1.0
hover-classstringbutton-hover指定按钮按下去的样式类。当 hover-class=“none” 时,没有点击态效果1.0.0
hover-stop-propagationbooleanfalse指定是否阻止本节点的祖先节点出现点击态1.5.0
hover-start-timenumber20按住后多久出现点击态,单位毫秒1.0.0
hover-stay-timenumber70手指松开后点击态保留时间,单位毫秒1.0.0
langstringen指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文1.3.0
session-fromstring会话来源,open-type="contact"时有效1.4.0
send-message-titlestring当前标题会话内消息卡片标题,open-type="contact"时有效1.5.0
send-message-pathstring当前分享路径会话内消息卡片点击跳转小程序路径,open-type="contact"时有效1.5.0
send-message-imgstring截图会话内消息卡片图片,open-type="contact"时有效1.5.0
app-parameterstring打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效1.9.5
show-message-cardbooleanfalse是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效1.5.0
phone-number-no-quota-toastbooleantrue当手机号快速验证或手机号实时验证额度用尽时,是否对用户展示“申请获取你的手机号,但该功能使用次数已达当前小程序上限,暂时无法使用”的提示,默认展示,open-type=“getPhoneNumber” 或 open-type=“getRealtimePhoneNumber” 时有效3.0.1
bindgetuserinfoeventhandle用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效1.3.0
bindcontacteventhandle客服消息回调,open-type="contact"时有效1.5.0
createliveactivityeventhandle新的一次性订阅消息下发机制回调,open-type=liveActivity时有效2.26.2
bindgetphonenumbereventhandle手机号快速验证回调,open-type=getPhoneNumber时有效。Tips:在触发 bindgetphonenumber 回调后应立即隐藏手机号按钮组件,或置为 disabled 状态,避免用户重复授权手机号产生额外费用1.2.0
bindgetrealtimephonenumbereventhandle手机号实时验证回调,open-type=getRealtimePhoneNumber 时有效。Tips:在触发 bindgetrealtimephonenumber 回调后应立即隐藏手机号按钮组件,或置为 disabled 状态,避免用户重复授权手机号产生额外费用2.24.4
binderroreventhandle当使用开放能力时,发生错误的回调,open-type=launchApp时有效1.9.5
bindopensettingeventhandle在打开授权设置页后回调,open-type=openSetting时有效2.0.7
bindlaunchappeventhandle打开 APP 成功的回调,open-type=launchApp时有效2.4.4
bindchooseavatareventhandle获取用户头像回调,open-type=chooseAvatar时有效2.21.2
bindagreeprivacyauthorizationeventhandle用户同意隐私协议事件回调,open-type=agreePrivacyAuthorization时有效 (Tips: 如果使用 onNeedPrivacyAuthorization 接口,需要在 bindagreeprivacyauthorization 触发后再调用 resolve({ event: “agree”, buttonId }))2.32.3

注:

  1. tip: button-hover 默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}
  2. tip: bindgetphonenumber 从1.2.0 开始支持,但是在1.5.3以下版本中无法使用wx.canIUse进行检测,建议使用基础库版本进行判断。
  3. tip: 在bindgetphonenumber 等返回加密信息的回调中调用 wx.login 登录,可能会刷新登录态。此时服务器使用 code 换取的 sessionKey 不是加密时使用的 sessionKey,导致解密失败。建议开发者提前进行 login;或者在回调中先使用 checkSession 进行登录态检查,避免 login 刷新登录态。
  4. tip: 从 2.21.2 起,对getPhoneNumber接口进行了安全升级,bindgetphonenumber 返回的信息中增加code参数,code是一个动态的令牌,开发者拿到code后需调用微信后台接口换取手机号。详情新版接口使用指南
  5. tip: 从 2.1.0 起,button 可作为原生组件的子节点嵌入,以便在原生组件上使用 open-type 的能力。
  6. tip: 目前设置了 form-type 的 button 只会对当前组件中的 form 有效。因而,将 button 封装在自定义组件中,而 form 在自定义组件外,将会使这个 button 的 form-type 失效。

二、不常用组件【看官方DOC】


  • 17
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值