picker-view设置了value,实际不生效。。。请问如何处理?
JS
//生成年月日时分秒
let date = new Date()
let years = []
let months = []
let days = []
let hours = []
let minutes = []
let seconds = []
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)
}
for (let i = 0; i <= 23; i++) {
hours.push(i)
}
for (let i = 0; i <= 59; i++) {
minutes.push(i)
seconds.push(i)
}
_this.setData({
years: years,
months: months,
days: days,
hours: hours,
minutes: minutes,
seconds: seconds,
followupdatetimeValue: [9999, 9, 2, 1, 21, 11],
})
WXML
<picker-view indicator-style="height: 50px;" style="width: 100%; height: 50vh;" value="{{followupdatetimeValue}}"
bindchange="followupdatetimeChange">
<picker-view-column>
<view wx:for="{{years}}" wx:for-item="item" style="line-height: 50px; text-align: center;">{{item}}年
</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{months}}" wx:for-item="item" wx:for-index="idx" style="line-height: 50px; text-align: center;">{{item}}月
</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{days}}" wx:for-item="item" style="line-height: 50px; text-align: center;">{{item}}日</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{hours}}" wx:for-item="item" style="line-height: 50px; text-align: center;">{{item}}时
</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{minutes}}" wx:for-item="item" style="line-height: 50px; text-align: center;">{{item}}分
</view>
</picker-view-column>
<picker-view-column>
<view wx:for="{{seconds}}" wx:for-item="item" style="line-height: 50px; text-align: center;">{{item}}秒
</view>
</picker-view-column>
</picker-view>
晕死,终于找到解决方法。。什么鬼。。。
setTimeout(() => {
_this.setData({
followupdatetimeValue: [19, 0, 1, 0, 0, 15] ,
})
}, 0);
我就另辟蹊径了 , 既然不能直接支持,就得用上骚操作
使用 if 属性 进行重新渲染
我是uni-app
<view v-if="f渲染" > <picker :value="f测试" /> </view>
this.f渲染 = false; this.$nextTick(() => { this.f渲染 = true; }); //-> 或者 使用延迟执行 setTimeout, 但是不推荐 使用不好会有白屏风险
感觉这是个 bug, lifetimes.ready 或者 pageLifetimes.show 中跑了 setDate 后,也都不生效
不建议使用延迟,使用延迟存在非常明显的闪屏问题。
我用setData的第二个参数
self.setData({ year, month }, () => self.setData({ pickerVal }));
setTimeout(() => {
this.pickerValue = [0, 0, 0]
}, 0)
这样写也不行啊,要用$set?我是uniapp
需要在followupdatetimeChange里获取值后,重新通过setData改变followupdatetimeValue的值。