fix: upload file-list is updated but without re-rendered (#2405) (#2460)

This commit is contained in:
msidolphin 2021-07-12 11:03:00 +08:00 committed by GitHub
parent e2f8f382c3
commit abd902acd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 15 deletions

View File

@ -10,7 +10,7 @@
>
<li
v-for="file in files"
:key="file"
:key="file.uid || file"
:class="['el-upload-list__item', 'is-' + file.status, focusing ? 'focusing' : '']"
tabindex="0"
@keydown.delete="!disabled && handleRemove($event, file)"

View File

@ -1,7 +1,6 @@
import { ref, watch } from 'vue'
import { NOOP } from '@vue/shared'
import isEqual from 'lodash/isEqual'
import cloneDeep from 'lodash/cloneDeep'
// Inline types
@ -21,7 +20,6 @@ function genUid(seed: number) {
export default (props: IUseHandlersProps) => {
let cachedFiles: UploadFile[] = []
const uploadFiles = ref<UploadFile[]>([])
const uploadRef = ref<UploadRef>(null)
@ -131,18 +129,14 @@ export default (props: IUseHandlersProps) => {
})
watch(() => props.fileList, (fileList: UploadFile[]) => {
if(!isEqual(cachedFiles, fileList)){
cachedFiles = []
uploadFiles.value = fileList.map(file => {
const cloneFile = cloneDeep(file)
cachedFiles.push(cloneFile)
return {
...cloneFile,
uid: file.uid || genUid(tempIndex++),
status: file.status || 'success',
}
})
}
uploadFiles.value = fileList.map(file => {
const cloneFile = cloneDeep(file)
return {
...cloneFile,
uid: file.uid || genUid(tempIndex++),
status: file.status || 'success',
}
})
}, {
immediate: true,
deep: true,