关于form验证upload组件必填required时,是否选择文件的解决方法 #7163
LK19931225
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
1.背景描述:做一个表单上传的需求,有一项是文件上传,且是必填项,使用a-upload组件
2.问题描述:使用过程中发现沿用官方的方式,类似于这样 ,使用prop加v-model的方式绑定,无法像输入框下拉框等组件那样被检测到
3.解决办法:使用手动上传方式,利用fileList加自定义上传customRequest,this.$refs.ruleForm.validate()校验即可
如下:
data里面
4.后记
由于维护的是好几年前vue2的项目,使用的antd-design-vue 1.6.3版本,这个版本表单还没支持a-upload的必填,需要自己处理,现如今antd-design-vue已到4.x版本,暂未使用到4.x,不知新版是否已支持upload组件在表单中校验(ps:在antd react版本中,form表单会通过value/onChange两个属性配合,默认收集upload上传的值,可以检测到文件是否上传了,能触发表单校验,无需自己维护)
Beta Was this translation helpful? Give feedback.
All reactions