Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于datetime组件的问题 #2379

Closed
iiiron opened this issue Jan 4, 2018 · 6 comments
Closed

关于datetime组件的问题 #2379

iiiron opened this issue Jan 4, 2018 · 6 comments

Comments

@iiiron
Copy link

iiiron commented Jan 4, 2018

datetime组件index.vue第195行,此处$emit了on-hide事件,传值是type

        onHide (type) {
          _this.$emit('update:show', false)
          _this.validate()
          _this.$emit('on-hide', type)
          if (type === 'cancel') {
            _this.$emit('on-cancel')
          }
          if (type === 'confirm') {
            _this.$emit('on-confirm')
          }
        },

datetime组件index.vue第263行,此处监听变量show的变化,调用了hide方法,传值是currentValue

    show (val) {
      if (val) {
        this.picker && this.picker.show(this.currentValue)
      } else {
        this.picker && this.picker.hide(this.currentValue)
      }
    },

这会导致,使用datatime组件时,当用户在on-hide的回调中修改show的值时,on-hide回调被执行两次,而且一次执行参数是type,另一次执行参数是currentValue。

还有个问题。此组件的on-change事件不会在滑动picker时触发,不触发也就算了,为什么on-change事件在on-hide事件后触发,这会导致on-hide事件无法优雅的获取到用户当前的选项。

@airyland
Copy link
Owner

airyland commented Jan 4, 2018

对于后一个问题,你需要理解一下交互,该组件是需要用户确认才关闭,关闭时才修改值,因此是 on-hide 先执行,on-change 后执行。建议用 on-change 事件来获取值而不是 on-hide。

@iiiron
Copy link
Author

iiiron commented Jan 4, 2018

那当用户点击空白或者取消按钮时,on-change事件也被调用,这逻辑不对吧。on-change这个名字,从概念上来说就应该是值发生变化时才触发,我只是打开了pop,但点击了取消或者空白处来关闭了pop,怎么能当作一次变化呢?

@iiiron
Copy link
Author

iiiron commented Jan 4, 2018

on-change要么是滑动选项时触发,要么是用户点击完成时触发。不能在点击空白和点击取消时触发。你们现在的处理,就像一个input框,当用户给了它焦点,又让它失去焦点,但什么都没有输入,这个input却触发了onchange事件。

还有。举个例子,PopupPicker组件是on-change在前,on-hide在后的。我想你们应该做到抽象一致。

@airyland
Copy link
Owner

airyland commented Jan 4, 2018

datetime 不依赖 popup-picker,没有所谓的抽象一致。在点击空白或者取消时触发这是 bug。
有空就来 pr 吧。

@iiiron
Copy link
Author

iiiron commented Jan 4, 2018

sorry,点击空白没有触发on-change,看错日志了。不过确实是on-hide有两种被回调的情况,参数还不一样

linhaobin added a commit to linhaobin/vux that referenced this issue Jan 11, 2018
linhaobin added a commit to linhaobin/vux that referenced this issue Jan 11, 2018
airyland pushed a commit that referenced this issue Jan 14, 2018
* datetime:fix `on-hide` event trigger twice #2379

* datetime:fix cannot set `show` to `true` initially
@hwjaaa
Copy link

hwjaaa commented Dec 28, 2018

-Datetime怎么选择当天的时间,控件显示为2018/12/12 12 12,这样的,而不是分成五列分开选

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants