Ver código fonte

Upload: add url prop to upload file when list-type changed (#13771)

HarlanLuo 6 anos atrás
pai
commit
c3e8b77d47
1 arquivos alterados com 14 adições e 0 exclusões
  1. 14 0
      packages/upload/src/index.vue

+ 14 - 0
packages/upload/src/index.vue

@@ -122,6 +122,20 @@ export default {
   },
 
   watch: {
+    listType(type) {
+      if (type === 'picture-card' || type === 'picture') {
+        this.uploadFiles.forEach(file => {
+          if (!file.url && file.raw) {
+            try {
+              file.url = URL.createObjectURL(file.raw);
+            } catch (err) {
+              console.error('[Element Error][Upload]', err);
+              return;
+            }
+          }
+        });
+      }
+    },
     fileList: {
       immediate: true,
       handler(fileList) {