Ver código fonte

Update index.vue

王新雷 4 anos atrás
pai
commit
cf58b5cca3
1 arquivos alterados com 11 adições e 5 exclusões
  1. 11 5
      src/components/Upload/index.vue

+ 11 - 5
src/components/Upload/index.vue

@@ -7,7 +7,7 @@
                      :headers="headers"
                      :headers="headers"
                      :show-file-list="false"
                      :show-file-list="false"
                      v-loading="uploadImgLoading"
                      v-loading="uploadImgLoading"
-                     accept=".jpg, .jpeg, .png"
+                     :accept="accept"
                      :on-success="handleImgSuccess"
                      :on-success="handleImgSuccess"
                      :on-error="handleUploadImgError"
                      :on-error="handleUploadImgError"
                      :before-upload="beforeImgUpload">
                      :before-upload="beforeImgUpload">
@@ -37,6 +37,12 @@ export default {
             // 组件状态
             // 组件状态
             type: String,
             type: String,
         },
         },
+        accept: {
+            type: String,
+            default() {
+                return 'jpg, .jpeg, .png'
+            }
+        },
         imageSizeM: { // 默认2M
         imageSizeM: { // 默认2M
             type: Number,
             type: Number,
             default() {
             default() {
@@ -54,17 +60,18 @@ export default {
             }
             }
         }
         }
     },
     },
-    mounted() {},
+    mounted() {
+        this.imgUrl = this.value
+    },
     methods: {
     methods: {
         beforeImgUpload (file) {
         beforeImgUpload (file) {
             const isImage = this.imageType[file.type];
             const isImage = this.imageType[file.type];
             const isLt2M = file.size / 1024 / 1024 < this.imageSizeM;
             const isLt2M = file.size / 1024 / 1024 < this.imageSizeM;
-            console.log(isImage, isLt2M)
             if (!isImage) {
             if (!isImage) {
                 this.$message.error("只能上传图片格式!");
                 this.$message.error("只能上传图片格式!");
             }
             }
             if (!isLt2M) {
             if (!isLt2M) {
-                this.$message.error("上传图片大小不能超过 2MB!");
+                this.$message.error(`上传图片大小不能超过 ${isLt2M}MB!`);
             }
             }
             if (isImage && isLt2M) {
             if (isImage && isLt2M) {
                 this.uploadImgLoading = true
                 this.uploadImgLoading = true
@@ -83,7 +90,6 @@ export default {
     },
     },
     watch: {
     watch: {
         value(newValue) {
         value(newValue) {
-            console.log(newValue);
             this.imgUrl = newValue
             this.imgUrl = newValue
         },
         },
     },
     },