-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
- I have searched the issues of this repository and believe that this is not a duplicate.
Version
undefined
Environment
ant-design-vue": "^3.0.0-beta.3 ""vue": "^3.2.31"
Reproduction link
Steps to reproduce
- 新建子组件input-demo,里面只使用a-input,组件绑定 @update:value接口, <a-input @update:value="onInputUpdate" />
2.新建组件,使用上面定义的子组件,也绑定@update:value接口给 <InputDemo @update:value="onParentUpdate" />
What is expected?
不应该把onUpdate:value作为props定义的接口,更不应该限定props.onUpdate:value只接受function,这不符合vue的范式。
vue3本身支持了attrs的透传,props的合并与event事件合并策略是不一样的。antd-vue的代码却采用了react式的处理方式(事件也是props,即函数的参数,事件通过onXXX回调范式作为props传入子组件,事件的合并需要用户自己控制),但vue中event和props是不用的,是会做区分的,props与event的合并策略也是不一样的,props合并采用的覆盖策略, event采用的是合并到Array的策略。因此antd-vue粗暴的阉割这个规则是不合适的。
况且antd-vue的代码中并没有真实的使用了props.onUpdate:value的值,仅仅是做了校验(只接受function),否则如果传了Array类型的数据就直接报错,运行异常了。见上面的例子,并没有渲染异常,只在console中给了warning,而且行为也是符合预期的,子组件的onInputUpdate和父组件中的onParentUpdate函数都会执行,但这种在开发模式下的waring看着很烦(正式环境这些的waring会被去掉,这是vue自身的能力)。
因此,要么删除这种无意义的校验,要么改成校验类型为 VueTypeValidableDef<fn | fn[] >
What is actually happening?
console中报错
[Vue warn]: Invalid prop: type check failed for prop "onUpdate:value". Expected Function, got Array
at <AInput value="123" onUpdate:value= (2) [ƒ, ƒ] >
at <AntInput onUpdate:value=fn >
at
请有点责任感,不要随随便便关issue,看明白问题的描述,确认问题是不是真实存在。
你可以以修改这个校验会破坏组件库的某些feature为由,拒绝修改,做一些对vue自身功能的阉割也不是特别不能接受。但以这不是问题为由简单的关闭issue,这不可取。我明白开源不易,用爱发电也不易,但也请虚心接受issue提的问题。