微信小程序常用组件view、text、image、button、checkbox、radio、swiper

view 组件是一个视图容器组件,类似于网页中的div

常用属性 和 官方文档链接

hover-class :指定按下去的样式类 

hover-start-time:按住后多久出现点击态,单位毫秒

<view hover-class="hover" hover-start-time="2000">组件view的hover-class属性</view>

text 文本组件

常用属性 和 官方文档链接

user-select:该属性代表文本是否可选(长按文本) 默认false

decode:该属性代表的文本内容的特殊符号是否解码默认false

<text user-select="true" decode="true">&gt;text组件,\n是否可选&lt;</text>

image 图片。支持 JPG、PNG、SVG、WEBP、GIF 等格式

常用属性 和 官方文档链接

src 属性 图片的引入地址属性

mode 常用值

scaleToFill缩放模式,不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素 
aspectFit缩放模式,保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来。 
aspectFill缩放模式,保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。 
widthFix缩放模式,宽度不变,高度自动变化,保持原图宽高比不变

注意:

  1. image组件默认的图片大小是宽320px ,高是240px。
  2. 程序发布不允许超过2m,不建议图片本地化,要求使用网络地址。推荐一个图床网址 https://imgurl.org/ 将本地图片上传到网络。
  3. aspectFit 这里的长边不是我们设定值的大小决定的(值大的不一定是长边),长边是谁先缩放到设定的值,谁是长边。
  4. aspectFill 缩放模式,保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。

button

button官方文档

常用属性列表

sizestringdefault按钮的大小1.0.0
typestringdefault按钮的样式类型1.0.0
plainbooleanfalse按钮是否镂空,背景色透明1.0.0
disabledbooleanfalse是否禁用1.0.0
loadingbooleanfalse名称前是否带 loading 图标1.0.0
open-typestring 微信开放能力

1.1.0

 open-type 常用属性值

contact打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息,具体说明1.1.0
share触发用户转发,使用前建议先阅读使用指引1.2.0
getPhoneNumber获取用户手机号,可以从bindgetphonenumber回调中获取到用户信息1.2.0
getUserInfo获取用户信息,可以从bindgetuserinfo回调中获取到用户信息1.3.0
launchApp打开APP,可以通过app-parameter属性设定向APP传的参数1.9.5
openSetting打开授权设置页2.0.7
feedback打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容

注:share 只能转发好友或者群聊 不能转发朋友圈

注:openSetting 查看权限 只能查看询问过的权限

示例

<button 
size="default"
type="primary"
plain=""
disabled=""
loading="true"
>加载按钮</button>
<button
  type="warn"
  open-type="contact"
  bindcontact="handleContact"
>contact客服会话</button>
<button
  type="primary"
  open-type="share"
>share转发不能发朋友圈</button>
<button
  type="primary"
  size="mini"
  open-type="getPhoneNumber"
  bindgetphonenumber="getphonenumber"
>getPhoneNumber获取手机号</button>

<button
  type="primary"
  open-type="getUserInfo"
  bindgetuserinfo = "getUserInfo"
>getUserInfo用户信息</button>

<button
  type="primary"
  open-type="openSetting"
>openSetting授权设置</button>

checkbox

checkbox官方文档

注:checkbox 必须结合checkbox-group组件使用

属性类型默认值必填说明最低版本
valuestring checkbox标识,选中时触发checkbox-group的 change 事件,并携带 checkbox的 value1.0.0
disabledbooleanfalse是否禁用1.0.0
checkedbooleanfalse当前是否选中,可用来设置默认选中1.0.0
colorstring#09BB07checkbox的颜色,同css的color1.0.0
<checkbox-group bindchange="changeCheckbox">
  <checkbox value="bj" color="#784515">北京</checkbox>
  <checkbox value="sh">上海</checkbox>
  <checkbox value="sz">深圳</checkbox>
</checkbox-group>

  changeCheckbox:function(e){
    console.log(e)
  }

radio

radio官方文档

注:radio组件必须结合radio-group组件使用

属性类型默认值必填说明最低版本
valuestring radio 标识。当该radio 选中时,radio-group 的 change 事件会携带radio的value1.0.0
checkedbooleanfalse当前是否选中1.0.0
disabledbooleanfalse是否禁用1.0.0
colorstring#09BB07radio的颜色,同css的color1.0.0
<radio-group bindchange="radioChange">
  <radio value="nan">男</radio>
  <radio value="nv">女</radio>
</radio-group>
radioChange:function(res){
    console.log(res)
  }

swiper

swiper官方文档

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

属性类型默认值必填说明最低版本
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
previous-marginstring"0px"前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值1.9.0
next-marginstring"0px"后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值1.9.0
snap-to-edgeboolean"false"当 swiper-item 的个数大于等于 2,关闭 circular 并且开启 previous-margin 或 next-margin 的时候,可以指定这个边距是否应用到第一个、最后一个元素2.12.1
display-multiple-itemsnumber1同时显示的滑块数量1.9.0
easing-functionstring"default"指定 swiper 切换缓动动画类型2.6.5
bindchangeeventhandle current 改变时会触发 change 事件,event.detail = {current, source}1.0.0
bindtransitioneventhandle swiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}
<swiper 
indicator-dots="true" 
indicator-color="orange" 
indicator-active-color="white"
autoplay="false"
current="2"
interval="3000"
duration="500"
circular="true"
previous-margin="20px"
next-margin="20px"
snap-to-edge="true"
display-multiple-items="1"
bindchange="swiperChange"
bindtransition='bindtransition'
>
  <swiper-item>
    <image src="https://ftp.bmp.ovh/imgs/2021/03/89e52ad717008760.jpg"  alt=""></image>
  </swiper-item>
  <swiper-item>
    <image src="https://ftp.bmp.ovh/imgs/2021/03/b09da3334f650bed.jpg"  alt=""></image>
  </swiper-item>
  <swiper-item>
    <image src="https://ftp.bmp.ovh/imgs/2021/03/f2b5f2af5c824216.jpg"  alt=""></image>
  </swiper-item>
  <swiper-item>
    <image src="https://ftp.bmp.ovh/imgs/2021/03/14e10e003886bac1.jpg"  alt=""></image>
  </swiper-item>
</swiper>

 

 

 

 

 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值