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

DatetimePicker.js 中的 clear 方法为什么不直接set value to null, 然后再emit出去? #2460

Open
msyesyan opened this issue Feb 1, 2018 · 1 comment

Comments

@msyesyan
Copy link

msyesyan commented Feb 1, 2018

请教一下,为什么 DatetimePicker.prototype.clear 方法不直接 this.value = null, 而一定要在所有引用Datetime 组件的地方手工传入 on-clear 函数?这样感觉有点麻烦且重复劳动, on-clear 函数应该是做在value清空时后续custom操作的地方。

src/components/datetime/datetimepicker.js

  clear () {
    const value = this.getValue()
    // this.value = null //这样写会有什么问题么?本来就是clear函数,清空value就是它应该做的事情

    if (this.config.onClear.call(this, null) === false) {
      return
    }

    this.hide('clear')
  }
@airyland
Copy link
Owner

airyland commented Feb 1, 2018

结合这个函数上方的 confirm 操作来看,这里是可以直接赋值 this.value 的。至于后面的 onClear 只是为了触发调用该 js 的 vue 实例做相关操作。

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

2 participants