0
点赞
收藏
分享

微信扫一扫

【Kevin Learn 小程序】-->picker-view

效果图

【Kevin Learn 小程序】-->picker-view_json

属性

参考:​​picker-view​​

代码

  1. app.js
//app.js
App({
onLaunch: function () {
console.log('App Launch')
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},
globalData: {
hasLogin: false
}
})
  1. app.json
{
"pages": [
"pages/picker-view/picker-view"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
  1. picker-view.js
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: [0, 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[2]]
})
}
})
  1. picker-view.json
{
"navigationBarTitleText": "picker-view 组件"
}
  1. picker-view.wxml
<view>
<view>{{year}}{{month}}{{day}}</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="*this" style="line-height: 50px">{{item}}</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{months}}" wx:key="*this" style="line-height: 50px">{{item}}</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{days}}" wx:key="*this" style="line-height: 50px">{{item}}</view>
</picker-view-column>
</picker-view>
</view>


举报

相关推荐

0 条评论