图片上传完美了
This commit is contained in:
parent
ec74a2d3de
commit
bf62105bc7
@ -13,8 +13,8 @@
|
|||||||
:headers="headers"
|
:headers="headers"
|
||||||
style="display: inline-block; vertical-align: top"
|
style="display: inline-block; vertical-align: top"
|
||||||
>
|
>
|
||||||
<img v-if="value" :src="value" class="avatar" />
|
<img v-if="value" :src="value|image" class="avatar" />
|
||||||
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -38,9 +38,14 @@ export default {
|
|||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
filters: {
|
||||||
|
image(value) {
|
||||||
|
return process.env.VUE_APP_BASE_API + "/common/file?fileName=" + value
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleUploadSuccess(res) {
|
handleUploadSuccess(res) {
|
||||||
this.$emit("input", res.url);
|
this.$emit("input", res.fileName);
|
||||||
this.loading.close();
|
this.loading.close();
|
||||||
},
|
},
|
||||||
handleBeforeUpload() {
|
handleBeforeUpload() {
|
||||||
@ -58,7 +63,6 @@ export default {
|
|||||||
this.loading.close();
|
this.loading.close();
|
||||||
},
|
},
|
||||||
handleRemove(file, fileList) {
|
handleRemove(file, fileList) {
|
||||||
console.log(file, fileList);
|
|
||||||
this.$emit("input", '');
|
this.$emit("input", '');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,24 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="component-upload-image">
|
<div class="component-upload-image">
|
||||||
<!-- <el-upload-->
|
|
||||||
<!-- :action="uploadImgUrl"-->
|
|
||||||
<!-- list-type="picture-card"-->
|
|
||||||
<!-- :on-success="handleUploadSuccess"-->
|
|
||||||
<!-- :before-upload="handleBeforeUpload"-->
|
|
||||||
<!-- :on-error="handleUploadError"-->
|
|
||||||
<!-- name="file"-->
|
|
||||||
<!-- :show-file-list="false"-->
|
|
||||||
<!-- :headers="headers"-->
|
|
||||||
<!-- style="display: inline-block; vertical-align: top"-->
|
|
||||||
<!-- >-->
|
|
||||||
<!-- <img v-if="value" :src="value| image" class="avatar"/>-->
|
|
||||||
<!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i>-->
|
|
||||||
<!-- </el-upload>-->
|
|
||||||
|
|
||||||
<el-upload
|
<el-upload
|
||||||
class="upload-demo"
|
class="upload-demo"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
:action="uploadImgUrl"
|
:action="uploadImgUrl"
|
||||||
|
auto-upload
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
:on-success="handleUploadSuccess"
|
:on-success="handleUploadSuccess"
|
||||||
:before-upload="handleBeforeUpload"
|
:before-upload="handleBeforeUpload"
|
||||||
@ -26,16 +13,21 @@
|
|||||||
:on-preview="handlePreview"
|
:on-preview="handlePreview"
|
||||||
:on-remove="handleRemove"
|
:on-remove="handleRemove"
|
||||||
name="file"
|
name="file"
|
||||||
|
multiple
|
||||||
|
:limit="5"
|
||||||
:file-list="fileList"
|
:file-list="fileList"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
list-type="picture">
|
list-type="picture">
|
||||||
|
|
||||||
<el-button size="small" type="primary">点击上传</el-button>
|
<el-button size="small" type="primary">点击上传</el-button>
|
||||||
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
|
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,最大限制5张</div>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {getToken} from "@/utils/auth";
|
import {getToken} from "@/utils/auth";
|
||||||
|
import {Message} from "element-ui";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {},
|
components: {},
|
||||||
@ -45,6 +37,7 @@ export default {
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + getToken(),
|
Authorization: "Bearer " + getToken(),
|
||||||
},
|
},
|
||||||
|
fileList: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
@ -59,17 +52,25 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
fileList() {
|
|
||||||
|
|
||||||
return this.value.split(',').map(x => {
|
|
||||||
|
|
||||||
return process.env.VUE_APP_BASE_API + "/common/file?fileName=" + x
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleUploadSuccess(res) {
|
handleUploadSuccess(res, file, fileList) {
|
||||||
this.$emit("input", res.fileName);
|
|
||||||
|
|
||||||
|
fileList = fileList.filter(x => x.response)
|
||||||
|
|
||||||
|
let temp = fileList.map(x => {
|
||||||
|
return x.response.fileName
|
||||||
|
})
|
||||||
|
|
||||||
|
let result = temp.join(',')
|
||||||
|
|
||||||
|
console.log(result)
|
||||||
|
|
||||||
|
this.$emit("input", result);
|
||||||
this.loading.close();
|
this.loading.close();
|
||||||
},
|
},
|
||||||
handleBeforeUpload() {
|
handleBeforeUpload() {
|
||||||
@ -87,10 +88,23 @@ export default {
|
|||||||
this.loading.close();
|
this.loading.close();
|
||||||
},
|
},
|
||||||
handleRemove(file, fileList) {
|
handleRemove(file, fileList) {
|
||||||
console.log(file, fileList);
|
let temp = fileList.map(x => {
|
||||||
|
return x.response.fileName
|
||||||
|
})
|
||||||
|
|
||||||
|
let result = temp.join(',')
|
||||||
|
this.$emit("input",result);
|
||||||
},
|
},
|
||||||
handlePreview(file) {
|
handlePreview(file) {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
|
},
|
||||||
|
handleExceed(file,fileList) {
|
||||||
|
Message({
|
||||||
|
message: "超出上传数量限制",
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {},
|
watch: {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user