Sfoglia il codice sorgente

现在上传照片的文件大小

梁展鹏 3 anni fa
parent
commit
db542fcc08
1 ha cambiato i file con 9 aggiunte e 4 eliminazioni
  1. 9 4
      src/components/Upload.vue

+ 9 - 4
src/components/Upload.vue

@@ -7,13 +7,14 @@
       :headers="myHeaders"
       list-type="picture-card"
       :multiple="false"
-      :limit="limit"
-      :file-list="imgList"
       :on-success="handleAvatarSuccess"
       :on-error="handleError"
       :on-progress="onProgress"
       :before-upload="handleBeforeUpload"
       :disabled="limit <= value.length"
+      accept="image/*"
+      :file-list="imgList"
+      :limit="limit"
     >
       <i slot="default" class="el-icon-plus" />
       <div slot="file" slot-scope="{ file }">
@@ -51,8 +52,7 @@
         </template> -->
 
     <template v-if="limit">
-      最多上传 <b style="color: #f56c6c">{{ limit }}</b
-      >张
+      最多上传 <b style="color: #f56c6c">{{ limit }}</b>张
     </template>
 
     <el-dialog :visible.sync="dialogVisible" :modal="false">
@@ -194,6 +194,11 @@ export default {
       this.dialogVisible = true;
     },
     handleBeforeUpload() {
+      const isLt100M = file.size / 1024 / 1024 > 0.5 && file.size / 1024 / 1024 < 5;
+      if (!isLt100M) {
+        this.$message.error("上传照片大小要在0.5MB ~ 5MB之间哦!");
+        return false;
+      }
       this.loading = this.$loading({
         lock: true,
         text: 'Loading',