您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详解微信小程序组件:picker滚动选择器

2024/3/18 6:59:50发布25次查看
picker滚动选择器组件说明:
picker:
滚动选择器,现支持三种选择器,通过mode属性来区分,
分别是普通选择器(mode = selector),时间选择器(mode = time),日期选择器(mode = date),
默认是普通选择器。
picker滚动选择器示例代码运行效果如下:
下面是wxml代码
<view class="page"> <view class="page__hd"> <text class="page__title">picker</text> <text class="page__desc">选择器</text> </view> <view class="page__bd"> <view class="section"> <view class="section__title">地区选择器</view> <picker bindchange="bindpickerchange" value="{{index}}" range="{{array}}"> <view class="picker"> 当前选择:{{array[index]}} </view> </picker> </view> <view class="section"> <view class="section__title">时间选择器</view> <picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindtimechange"> <view class="picker"> 当前选择: {{time}} </view> </picker> </view> <view class="section"> <view class="section__title">日期选择器</view> <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="binddatechange"> <view class="picker"> 当前选择: {{date}} </view> </picker> </view> </view> </view>
下面是js代码
page({ data: { array: ['中国', '美国', '巴西', '日本'], index: 0, date: '2016-09-01', time: '12:01' }, bindpickerchange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setdata({ index: e.detail.value }) }, binddatechange: function(e) { this.setdata({ date: e.detail.value }) }, bindtimechange: function(e) { this.setdata({ time: e.detail.value }) } })
下面是wxss代码
.page { min-height: 100%; flex: 1; background-color: #fbf9fe; font-size: 32rpx; font-family: -apple-system-font,helvetica neue,helvetica,sans-serif; overflow: hidden; } .page__hd{ padding: 50rpx 50rpx 100rpx 50rpx; text-align: center; } .page__title{ display: inline-block; padding: 20rpx 40rpx; font-size: 32rpx; color: #aaaaaa; border-bottom: 1px solid #cccccc; } .page__desc{ display: none; margin-top: 20rpx; font-size: 26rpx; color: #bbbbbb; } .picker{ padding: 26rpx; background-color: #ffffff; } .section{ margin-bottom: 80rpx; } .section__title{ margin-bottom: 16rpx; padding-left: 30rpx; padding-right: 30rpx; }
picker滚动选择器的主要属性:
普通选择器:(mode = selector)
属性名
类型
默认值
说明
range array [ ] mode为 selector 时,range 有效
value number 0 mode为 selector 时,是数字,表示选择了 range 中的第几个,从0开始。
bindchange eventhandle
value改变时触发change事件,event.detail = {value: value}
时间选择器:(mode = time)
属性名
类型
默认值
说明
value string
表示选中的时间,格式为”hh:mm”
start string
表示有效时间范围的开始,字符串格式为”hh:mm”
end string
表示有效时间范围的结束,字符串格式为”hh:mm”
bindchange eventhandle
value改变时触发change事件,event.detail = {value: value}
日期选择器:(mode = date)
属性名
类型
默认值
说明
value string 0 表示选中的日期,格式为”yyyy-mm-dd”
start string
表示有效日期范围的开始,字符串格式为”yyyy-mm-dd”
end string
表示有效日期范围的结束,字符串格式为”yyyy-mm-dd”
fields string day 有效值year,month,day,表示选择器的粒度
bindchange eventhandle
value改变时触发change事件,event.detail = {value: value}
以上就是详解微信小程序组件:picker滚动选择器的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product