fix(upload): fix transition error trigger when fileList is static (#1686)

This commit is contained in:
Ryan2128 2021-03-27 19:07:50 +08:00 committed by GitHub
parent e7bff99ece
commit f916bf0cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
import { ref, watch } from 'vue'
import { NOOP } from '@vue/shared'
import isEqual from 'lodash/isEqual'
import cloneDeep from 'lodash/cloneDeep'
// Inline types
import type { ListType, UploadFile, ElFile, ElUploadProgressEvent, IUseHandlersProps } from './upload.type'
@ -19,6 +21,7 @@ function genUid(seed: number) {
export default (props: IUseHandlersProps) => {
let cachedFiles: UploadFile[] = []
const uploadFiles = ref<UploadFile[]>([])
const uploadRef = ref<UploadRef>(null)
@ -128,11 +131,18 @@ export default (props: IUseHandlersProps) => {
})
watch(() => props.fileList, (fileList: UploadFile[]) => {
uploadFiles.value = fileList.map(file => {
file.uid = file.uid || genUid(tempIndex++)
file.status = file.status || 'success'
return file
})
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',
}
})
}
}, {
immediate: true,
deep: true,