微信小程序官方组件展示之表单组件picker-view源码
转载
以下将展示微信小程序之表单组件picker-view源码官方组件能力,组件样式仅供参考,开发者可根据自身需求定义组件样式,具体属性参数详见小程序开发文档。
功能描述:
嵌入页面的滚动选择器。其中只可放置 picker-view-column组件,其它节点不会显示。
属性说明:
Bug
& Tip
1.tip:
滚动时在 iOS 自带振动反馈,可在系统设置 -> 声音与触感 -> 系统触感反馈中关闭
示例代码:
JAVASCRIPT:
const date = new Date()
const years = []
const months = []
const days = []
for (let i = 1990; i <= date.getFullYear(); i++) {
years.push(i)
}
for (let i = 1; i <= 12; i++) {
months.push(i)
}
for (let i = 1; i <= 31; i++) {
days.push(i)
}
Page({
onShareAppMessage() {
return {
title: 'picker-view',
path: 'page/component/pages/picker-view/picker-view'
}
},
data: {
years,
year: date.getFullYear(),
months,
month: 2,
days,
day: 2,
value: [9999, 1, 1],
isDaytime: true,
},
bindChange(e) {
const val = e.detail.value
this.setData({
year: this.data.years[val[0]],
month: this.data.months[val[1]],
day: this.data.days[val[2]],
isDaytime: !val[3]
})
}
})
WXML:
<view class="container">
<view class="page-body">
<view class="selected-date">{{year}}年{{month}}月{{day}}日{{isDaytime ? "白天" : "夜晚"}}</view>
<picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChange">
<picker-view-column>
<view wx:for="{{years}}" wx:key="{{years}}" style="line-height: 50px; text-align: center;">{{item}}年</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{months}}" wx:key="{{months}}" style="line-height: 50px; text-align: center;">{{item}}月</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{days}}" wx:key="{{days}}" style="line-height: 50px; text-align: center;">{{item}}日</view>
</picker-view-column>
<picker-view-column>
<view class="icon-container">
<image class="picker-icon" src="../lib/daytime.png" />
</view>
<view class="icon-container">
<image class="picker-icon" src="../lib/night.png" />
</view>
</picker-view-column>
</picker-view>
</view>
</view>
版权声明:
本站所有内容均由互联网收集整理、上传,如涉及版权问题,请联系我们第一时间处理。
原文链接地址:https://developers.weixin.qq.com/miniprogram/dev/component/picker-view.html