@@ -10,9 +10,10 @@ import Button from '../../button';
10
10
import ListItem from './ListItem' ;
11
11
import type { HTMLAttributes } from 'vue' ;
12
12
import {
13
+ triggerRef ,
14
+ watch ,
13
15
computed ,
14
16
defineComponent ,
15
- getCurrentInstance ,
16
17
onMounted ,
17
18
shallowRef ,
18
19
watchEffect ,
@@ -46,15 +47,26 @@ export default defineComponent({
46
47
} ) ,
47
48
setup ( props , { slots, expose } ) {
48
49
const motionAppear = shallowRef ( false ) ;
49
- const instance = getCurrentInstance ( ) ;
50
50
onMounted ( ( ) => {
51
51
motionAppear . value == true ;
52
52
} ) ;
53
+ const mergedItems = shallowRef ( [ ] ) ;
54
+ watch (
55
+ ( ) => props . items ,
56
+ ( val = [ ] ) => {
57
+ mergedItems . value = val . slice ( ) ;
58
+ } ,
59
+ {
60
+ immediate : true ,
61
+ deep : true ,
62
+ } ,
63
+ ) ;
53
64
watchEffect ( ( ) => {
54
65
if ( props . listType !== 'picture' && props . listType !== 'picture-card' ) {
55
66
return ;
56
67
}
57
- ( props . items || [ ] ) . forEach ( ( file : InternalUploadFile ) => {
68
+ let hasUpdate = false ;
69
+ ( props . items || [ ] ) . forEach ( ( file : InternalUploadFile , index ) => {
58
70
if (
59
71
typeof document === 'undefined' ||
60
72
typeof window === 'undefined' ||
@@ -69,11 +81,17 @@ export default defineComponent({
69
81
if ( props . previewFile ) {
70
82
props . previewFile ( file . originFileObj as File ) . then ( ( previewDataUrl : string ) => {
71
83
// Need append '' to avoid dead loop
72
- file . thumbUrl = previewDataUrl || '' ;
73
- instance . update ( ) ;
84
+ const thumbUrl = previewDataUrl || '' ;
85
+ if ( thumbUrl !== file . thumbUrl ) {
86
+ mergedItems . value [ index ] . thumbUrl = thumbUrl ;
87
+ hasUpdate = true ;
88
+ }
74
89
} ) ;
75
90
}
76
91
} ) ;
92
+ if ( hasUpdate ) {
93
+ triggerRef ( mergedItems ) ;
94
+ }
77
95
} ) ;
78
96
79
97
// ============================= Events =============================
@@ -177,7 +195,6 @@ export default defineComponent({
177
195
listType,
178
196
locale,
179
197
isImageUrl : isImgUrl ,
180
- items = [ ] ,
181
198
showPreviewIcon,
182
199
showRemoveIcon,
183
200
showDownloadIcon,
@@ -190,6 +207,7 @@ export default defineComponent({
190
207
appendActionVisible,
191
208
} = props ;
192
209
const appendActionDom = appendAction ?.( ) ;
210
+ const items = mergedItems . value ;
193
211
return (
194
212
< TransitionGroup { ...transitionGroupProps . value } tag = "div" >
195
213
{ items . map ( file => {
0 commit comments