微信小程序picker-view组件详解实例代码

高洛峰
Release: 2017-03-21 16:50:50
Original
2942 people have browsed it

这篇文章主要介绍了微信小程序 picker-view 组件详解及简单实例的相关资料,需要的朋友可以参考下

实现效果图:

微信小程序picker-view组件详解实例代码

嵌入页面的滚动选择器

属性名类型默认值说明
valueNumber Array 数组中的数字依次表示 picker-view 内的 picker-view-colume 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
indicator-styleString 设置选择器中间选中框的样式
bindchangeEventHandle 当滚动选择,value 改变时触发 change 事件,event.detail = {value: value};value为数组,表示 picker-view 内的 picker-view-column 当前选择的是第几项(下标从 0 开始)

注意:其中只可放置组件,其他节点不会显示。

picker-view-column

仅可放置于中,其孩子节点的高度会自动设置成与picker-view的选中框的高度一致

示例代码:



 {{year}}年{{month}}月{{day}}日
 
 
 {{item}}年
 
 
 {{item}}月
 
 
 {{item}}日
 
 
Copy after login


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({
 data: {
 years: years,
 year: date.getFullYear(),
 months: months,
 month: 2,
 days: days,
 day: 2,
 year: date.getFullYear(),
 value: [9999, 1, 1],
 },
 bindChange: function(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[1]]
 })
 }
})
Copy after login

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

The above is the detailed content of 微信小程序picker-view组件详解实例代码. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!