This commit is contained in:
sakuya 2021-05-19 00:40:31 +08:00
parent 9e13f52a1d
commit 6cfe46c60b
2 changed files with 27 additions and 25 deletions

View File

@ -8,7 +8,7 @@
</div>
<div v-else>
<div class="mask">
<span class="del" @click.stop="del"><i class="el-icon-delete"></i></span>
<span class="del" @click.stop="del(index)"><i class="el-icon-delete"></i></span>
</div>
<el-image class="image" :src="file.url" :preview-src-list="[file.url]" fit="cover" hide-on-click-modal append-to-body></el-image>
</div>
@ -17,7 +17,7 @@
</div>
<div class="sc-upload-uploader">
<el-upload ref="upload" :action="action" :accept="accept" multiple :show-file-list="true" :before-upload="before" :on-success="success" :on-error="error">
<el-upload ref="upload" :action="action" :accept="accept" multiple :show-file-list="true" :file-list="defaultList" :before-upload="before" :on-success="success" :on-remove="remove" :on-error="error">
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
</div>
@ -33,35 +33,39 @@
},
data(){
return {
defaultList: this.toArr(this.modelValue),
fileList: []
}
},
watch:{
// modelValue(){
// this.fileList = this.toArr(this.modelValue);
// },
// fileList: {
// handler(){
// this.$emit('update:modelValue', this.toStr(this.fileList));
// },
// deep: true
// }
modelValue(){
},
fileList: {
handler(val){
this.$emit('update:modelValue', this.toStr(val));
},
deep: true
}
},
mounted() {
this.fileList = this.toArr(this.modelValue);
this.$refs.upload.uploadFiles = this.fileList
this.fileList = this.$refs.upload.uploadFiles
},
methods: {
//
toArr(str){
var _arr = [];
var arr = str.split(",");
arr.forEach(item => {
_arr.push({
name: "F",
status: "success",
url: item
})
if(item){
_arr.push({
name: "F",
status: "success",
url: item
})
}
})
return _arr;
},
@ -75,15 +79,13 @@
return str;
},
before(){
this.fileList = this.$refs.upload.uploadFiles;
this.fileList.forEach(item => {
if(item.status!='success'){
item.tempURL = URL.createObjectURL(item.raw);
}
})
console.log(this.$refs.upload.uploadFiles);
},
success(res, file){
file.url = res.data.src
},
remove(){
},
error(err){
this.$notify.error({

View File

@ -52,7 +52,7 @@
uploadUrl: this.$API.demo.upload.url,
imgurl: "images/avatar.jpg",
avatar: "",
imgs: "images/avatar.jpg,images/avatar.jpg",
imgs: "images/avatar.jpg,images/avatar2.gif,images/avatar3.gif",
form: {
img1: "",
img2: "",