Selaa lähdekoodia

新增文件大小传参 和 文件上传进度条

wuhao 3 vuotta sitten
vanhempi
commit
310cf4275a
1 muutettua tiedostoa jossa 13 lisäystä ja 14 poistoa
  1. 13 14
      src/components/Upload/index.vue

+ 13 - 14
src/components/Upload/index.vue

@@ -1,6 +1,7 @@
 <template>
   <div>
-    <el-upload :disabled="disabledUpload"
+    <el-upload
+      :disabled="disabledUpload"
       ref="upload"
       v-if="type === 'file' ? true : hideUpload"
       :action="action"
@@ -63,17 +64,15 @@ export default {
       // 禁用上传按钮
       disabledUpload: false,
       // 按钮标题
-      title: '上传文件',
+      title: "上传文件",
       // 图片
       newUrl: "",
     };
   },
   watch: {
     url(val) {
-      if (val) {
-        this.newUrl = val;
-        this.hideUpload = false;
-      }
+      this.newUrl = val;
+      this.hideUpload = val ? false : true
     },
   },
   mounted() {
@@ -91,25 +90,25 @@ export default {
     // 上传服务器之前提交文件
     beforeUpload(file) {
       this.data.multipartFile = file;
-      this.size = file.size
-      this.disabledUpload = true
+      this.size = file.size;
+      this.disabledUpload = true;
     },
 
     // 上传成功
     onSuccess(file) {
       this.hideUpload = false;
-      this.disabledUpload = false
-      this.newUrl = file.data
-      this.title = '上传成功'
+      this.disabledUpload = false;
+      this.newUrl = file.data;
+      this.title = "上传成功";
       this.$emit("success", {
         file: this.newUrl,
-        size: this.size
+        size: this.size,
       });
     },
 
     // 上传时 进度条
-    onProgress(file){
-      this.title = `${parseInt(file.percent - 1)}%`
+    onProgress(file) {
+      this.title = `${parseInt(file.percent - 1)}%`;
     },
 
     // 删除