使用微信小程序设计下拉菜单,发现官方文档中关于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,
months: months,
days: days,
//默认的顶部日期
year: date.getFullYear(),
month: date.getMonth()+1,
day: date.getDat