Vant: [Bug Report] DatetimePicker(type=time)修改 value 后未触发渲染

Created on 29 Dec 2018  ·  5Comments  ·  Source: youzan/vant

Describe the bug
每次打开DatetimePicker,默认时间都是第一次打开设置的值,如下图,当我点击13:21时,显示正常,关闭再点击8:15时,currentDate已经改变为8:15,但是显示的还是13:21。

Screenshots
1546053076 1
1546053097 1

代码如下:
1

Environment

  • Device:
  • Browser:
  • Vant Version: 1.5.0

Reproduce
Provide the steps to reproduce and if possible a minimal demo of the problem via jsfiddle.
https://jsfiddle.net/dfarLdko/522/

🐞 bug

Most helpful comment

我认为你确实发现了一个问题,v-model的修改,没有响应式的被datetime-picker渲染,也许是vant设计的意图,也许是issue

临时解决方案
你可以在template里给van-datetime-picker 加一个attribute ref='picker',然后加一个watcher

watch: {
        currentDate(val) {
          if(this.$refs.picker) this.$refs.picker.updateColumnValue(this.$refs.picker.correctValue(val))
        }
      },

还是那句话,我认为这不是一个正确的处理方式,因为这已经使用了vant文档对外公开的api以外的内容,仅仅是临时方案,解决你着急的需求。

同时,也希望vant团队能够看看,是否有正确方法或者确实这是一个问题。 @chenjiahan

All 5 comments

我认为你确实发现了一个问题,v-model的修改,没有响应式的被datetime-picker渲染,也许是vant设计的意图,也许是issue

临时解决方案
你可以在template里给van-datetime-picker 加一个attribute ref='picker',然后加一个watcher

watch: {
        currentDate(val) {
          if(this.$refs.picker) this.$refs.picker.updateColumnValue(this.$refs.picker.correctValue(val))
        }
      },

还是那句话,我认为这不是一个正确的处理方式,因为这已经使用了vant文档对外公开的api以外的内容,仅仅是临时方案,解决你着急的需求。

同时,也希望vant团队能够看看,是否有正确方法或者确实这是一个问题。 @chenjiahan

@multics 非常感谢你的回答,我是做的webApp,假期前为了上线,选择了原生的时间选择(安卓系统自带的时间选择有点不太好,之前摒弃了),不知道作者为啥一直没给个回复。。。再次感谢你,这可能会成为一个备选方案。

感谢反馈,元旦没来得及处理,会在下个版本修复

@chenjiahan 好的~

已在 1.5.2 版本修复

Was this page helpful?
0 / 5 - 0 ratings