mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-12 10:45:10 +08:00
fix(upload): fix transition error trigger when fileList is static (#1686)
This commit is contained in:
parent
e7bff99ece
commit
f916bf0cf6
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user