فهرست منبع

修改上传图片相关bug

蒋吉兆 3 سال پیش
والد
کامیت
63af7ee4cb
2فایلهای تغییر یافته به همراه7 افزوده شده و 10 حذف شده
  1. 6 9
      web/src/components/upload/image.vue
  2. 1 1
      web/src/view/example/upload/upload.vue

+ 6 - 9
web/src/components/upload/image.vue

@@ -1,10 +1,3 @@
-<!--
-  <div>
-    带压缩的上传
-    <upload-image v-model="imageUrl" :fileSize="512" />
-    已上传文件 {{ imageUrl }}
-  </div>
--->
 
 <template>
   <div>
@@ -17,7 +10,7 @@
       :before-upload="beforeImageUpload"
       :multiple="false"
     >
-      <img v-if="imageUrl" :src="imageUrl" class="image">
+      <img v-if="imageUrl" :src="showImageUrl" class="image">
       <i v-else class="el-icon-plus image-uploader-icon" />
     </el-upload>
   </div>
@@ -53,7 +46,10 @@ export default {
     }
   },
   computed: {
-    ...mapGetters('user', ['userInfo', 'token'])
+    ...mapGetters('user', ['userInfo', 'token']),
+    showImageUrl() {
+      return (this.imageUrl && this.imageUrl.slice(0, 4) !== 'http') ? path + this.imageUrl : this.imageUrl
+    }
   },
   methods: {
     beforeImageUpload(file) {
@@ -70,6 +66,7 @@ export default {
       const { data } = res
       if (data.file) {
         this.$emit('change', data.file.url)
+        this.$emit('on-success')
       }
     }
   }

+ 1 - 1
web/src/view/example/upload/upload.vue

@@ -17,7 +17,7 @@
         </el-col>
         <el-col :span="12">
           带压缩的上传, (512(k)为压缩限制)
-          <upload-image v-model="imageUrl" :file-size="512" :max-w-h="1080" />
+          <upload-image v-model="imageUrl" :file-size="512" :max-w-h="1080" @on-success="getTableData" />
           已上传文件 {{ imageUrl }}
         </el-col>
       </el-row>