Browse Source

Update image.vue

修复上传图片组件bug
main
听风 4 years ago
committed by GitHub
parent
commit
bdd6b9950f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      web/src/components/upload/image.vue

9
web/src/components/upload/image.vue

@ -13,6 +13,7 @@
<el-upload <el-upload
class="image-uploader" class="image-uploader"
:action="`${path}/fileUploadAndDownload/upload`" :action="`${path}/fileUploadAndDownload/upload`"
:headers="{ 'x-token': token }"
:show-file-list="false" :show-file-list="false"
:on-success="handleImageSuccess" :on-success="handleImageSuccess"
:before-upload="beforeImageUpload" :before-upload="beforeImageUpload"
@ -25,6 +26,7 @@
</template> </template>
<script> <script>
const path = process.env.VUE_APP_BASE_API; const path = process.env.VUE_APP_BASE_API;
import { mapGetters } from "vuex";
import ImageCompress from "@/utils/image.js"; import ImageCompress from "@/utils/image.js";
export default { export default {
name: "upload-image", name: "upload-image",
@ -51,6 +53,9 @@ export default {
path: path, path: path,
}; };
}, },
computed: {
...mapGetters("user", ["userInfo", "token"]),
},
methods: { methods: {
beforeImageUpload(file) { beforeImageUpload(file) {
let isRightSize = file.size / 1024 < this.fileSize; let isRightSize = file.size / 1024 < this.fileSize;
@ -65,7 +70,7 @@ export default {
// this.imageUrl = URL.createObjectURL(file.raw); // this.imageUrl = URL.createObjectURL(file.raw);
const { data } = res; const { data } = res;
if (data.file) { if (data.file) {
this.$emit("change", data.file.url);
this.$emit("change", this.path + data.file.url);
} }
}, },
}, },
@ -97,4 +102,4 @@ export default {
height: 178px; height: 178px;
display: block; display: block;
} }
</style>
</style>
Loading…
Cancel
Save