学习微信小程序的下拉列表控件-picker

1、创建一个空白工程

2、index.wxml中写上picker布局:

复制代码
<!--index.wxml-->
<view class="container">
  <picker mode="selector" range="{{array}}" bindchange="bindPickerChange">
    <view class="picker">
      当前选择:{{array[index]}}
    </view>
  </picker>
</view>

3、index.wxss中添加wxml中引入的样式:

复制代码
/**index.wxss**/
.container {
  display:flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100rpx;
}
.picker {
  padding: 20rpx;
  border: 1rpx solid #ccc;
  border-radius: 5rpx;
  margin-top: 20rpx;
}

4、index.js中添加数据(数组array),和列表选择切换的响应函数:

复制代码
// index.js
Page({
  data: {
    array: ['选项1','选项2','选项3','选项4'],
    index:0
  },
  bindPickerChange(e){
    console.log(e);
    this.setData({
      index:e.detail.value
    });
  }
})

5、编译,看效果,o了。

picker绑定对象数组遇到问题:

https://mp.csdn.net/mp_blog/creation/editor/145183341

相关推荐
云起SAAS16 小时前
设备质保保修维修保质包换期查询H5抖音快手微信小程序看广告流量主开源
微信小程序·小程序
程序媛徐师姐21 小时前
Java基于微信小程序的线上教育商城,附源码+文档说明
java·微信小程序·线上教育商城小程序·java线上教育商城小程序·线上教育商城微信小程序·线上教育小程序·线上教育微信小程序
peachSoda71 天前
小程序图片加载优化方案
前端·微信小程序·小程序
努力成为包租婆1 天前
【微信小程序-内嵌H5,微信开发工具上-页面没有更新】
微信小程序·小程序
计算机徐师兄1 天前
Java基于SSM的校园顺路代送微信小程序【附源码、文档说明】
java·微信小程序·ssm·校园顺路代送微信小程序·校园顺路代送·顺路代送微信小程序·java校园顺路代送微信小程序
百万蹄蹄向前冲1 天前
支付宝 VS 微信 小程序差异
前端·后端·微信小程序
人生导师yxc1 天前
微信小程序接入支付宝沙箱支付(http请求)
微信小程序·小程序
云起SAAS1 天前
日历黄历八字排盘紫微斗数奇门遁甲姓名分析号码吉凶命理抖音快手微信小程序看广告流量主开源
微信小程序·小程序·ai编程·看广告变现轻·日历黄历八字排盘紫微斗数
heyCHEEMS2 天前
用 分段渲染 解决小程序长列表卡顿问题
前端·微信小程序
qq_12498707532 天前
基于springboot的驾校预约管理小程序(源码+论文+部署+安装)
spring boot·微信小程序·小程序·毕业设计·计算机毕业设计·毕业设计源码