@@ -10,9 +10,10 @@ import Button from '../../button';
1010import ListItem from './ListItem' ;
1111import type { HTMLAttributes } from 'vue' ;
1212import {
13+ triggerRef ,
14+ watch ,
1315 computed ,
1416 defineComponent ,
15- getCurrentInstance ,
1617 onMounted ,
1718 shallowRef ,
1819 watchEffect ,
@@ -46,15 +47,26 @@ export default defineComponent({
4647 } ) ,
4748 setup ( props , { slots, expose } ) {
4849 const motionAppear = shallowRef ( false ) ;
49- const instance = getCurrentInstance ( ) ;
5050 onMounted ( ( ) => {
5151 motionAppear . value == true ;
5252 } ) ;
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+ ) ;
5364 watchEffect ( ( ) => {
5465 if ( props . listType !== 'picture' && props . listType !== 'picture-card' ) {
5566 return ;
5667 }
57- ( props . items || [ ] ) . forEach ( ( file : InternalUploadFile ) => {
68+ let hasUpdate = false ;
69+ ( props . items || [ ] ) . forEach ( ( file : InternalUploadFile , index ) => {
5870 if (
5971 typeof document === 'undefined' ||
6072 typeof window === 'undefined' ||
@@ -69,11 +81,17 @@ export default defineComponent({
6981 if ( props . previewFile ) {
7082 props . previewFile ( file . originFileObj as File ) . then ( ( previewDataUrl : string ) => {
7183 // 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+ }
7489 } ) ;
7590 }
7691 } ) ;
92+ if ( hasUpdate ) {
93+ triggerRef ( mergedItems ) ;
94+ }
7795 } ) ;
7896
7997 // ============================= Events =============================
@@ -177,7 +195,6 @@ export default defineComponent({
177195 listType,
178196 locale,
179197 isImageUrl : isImgUrl ,
180- items = [ ] ,
181198 showPreviewIcon,
182199 showRemoveIcon,
183200 showDownloadIcon,
@@ -190,6 +207,7 @@ export default defineComponent({
190207 appendActionVisible,
191208 } = props ;
192209 const appendActionDom = appendAction ?.( ) ;
210+ const items = mergedItems . value ;
193211 return (
194212 < TransitionGroup { ...transitionGroupProps . value } tag = "div" >
195213 { items . map ( file => {
0 commit comments