Skip to content

Upload组件与Form组件结合有问题 #925

@luichooy

Description

@luichooy
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.3.8

Environment

vue2.6.6

Reproduction link

https://vue.ant.design/components/form-cn/#components-form-demo-other-form-controls

Steps to reproduce

  1. 在Form组件内部使用Upload组件使用v-decorator="['dragger', { valuePropName: 'fileList', getValueFromEvent: normFile, }]"
  2. 选择一张图片后,然后调用 this.form.resetFields()
  3. 然后重新选择图片
  4. 报错

What is expected?

修复

What is actually happening?

此情况下源码

reBeforeUpload(file, fileList) {
if (!this.beforeUpload) {
return true;
}
const result = this.beforeUpload(file, fileList);
if (result === false) {
this.onChange({
file,
fileList: uniqBy(this.sFileList.concat(fileList.map(fileToObject)), item => item.uid),
});
return false;
} else if (result && result.then) {
return result;
}
return true;
},

中concat处报错。


原因是 form.resetFields() 将 fileList 置为 undefined, 而源码中又watch了 fileList,从而导致 sFileList 变为 undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions