Commit 1dc62be1 authored by dcy's avatar dcy

封装上传图片和视频

parent 6df8d884
<template> <template>
<div class="component-upload-image"> <div class="component-upload-image">
<div style="display: flex;flex-wrap: wrap "> <div style="display: flex;flex-wrap: wrap ">
<div v-for="(item, index) in fileList " :key="index" style="height: 148px; width:148px; border:1px solid;margin:5px 10px"> <div v-for="(item, index) in fileList " :key="index" style="height: 148px; width:148px; margin:5px 10px;position: relative;box-sizing: border-box;">
<el-image style="height: 148px; width:148px;" fit="fit" :src="item.url"> <el-image @click="dialogImageUrl = item.url; dialogVisible = true; " style="height: 148px; width:148px;" fit="fit" :src="item.url">
<video controls width="148px" height="148px" slot="error" :src="item.url" ></video> <video controls width="148px" height="148px" slot="error" :src="item.url" ></video>
</el-image> </el-image>
<div @click="handleRemove(index)" class="el-icon-error" style="font-size: 25px;cursor: pointer;position: absolute;right: -10px; top: -10px" ></div>
</div> </div>
<div> <div>
<el-upload <el-upload
...@@ -15,7 +16,6 @@ ...@@ -15,7 +16,6 @@
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:on-error="handleUploadError" :on-error="handleUploadError"
name="file" name="file"
:on-remove="handleRemove"
:show-file-list="false" :show-file-list="false"
:headers="headers" :headers="headers"
:on-preview="handlePictureCardPreview" :on-preview="handlePictureCardPreview"
...@@ -79,7 +79,7 @@ export default { ...@@ -79,7 +79,7 @@ export default {
headers: { headers: {
Authorization: "Bearer " + getToken(), Authorization: "Bearer " + getToken(),
}, },
fileList: [] fileList: [],
}; };
}, },
watch: { watch: {
...@@ -105,7 +105,8 @@ export default { ...@@ -105,7 +105,8 @@ export default {
} }
}, },
deep: true, deep: true,
immediate: true immediate: true,
} }
}, },
computed: { computed: {
...@@ -116,12 +117,10 @@ export default { ...@@ -116,12 +117,10 @@ export default {
}, },
methods: { methods: {
// 删除图片 // 删除图片
handleRemove(file, fileList) { handleRemove(index) {
const findex = this.fileList.map(f => f.name).indexOf(file.name); this.fileList.splice(index, 1);
if(findex > -1) {
this.fileList.splice(findex, 1);
this.$emit("input", this.listToString(this.fileList)); this.$emit("input", this.listToString(this.fileList));
}
}, },
// 上传成功回调 // 上传成功回调
handleUploadSuccess(res) { handleUploadSuccess(res) {
...@@ -202,6 +201,7 @@ export default { ...@@ -202,6 +201,7 @@ export default {
opacity: 0; opacity: 0;
transform: translateY(0); transform: translateY(0);
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment