点击删除按钮后会报错 并且预览无图片显示
代码:
<!-- 添加图片 -->
<el-upload
action="#"
:show-file-list="false"
:auto-upload="false"
accept=".png,.jpg,.jpeg"
:on-change="onImportFileChange"
>
<el-button type="primary" icon="el-icon-plus">新增</el-button>
</el-upload>
<!-- 显示图片列表 -->
<div class="add-image-list">
<div v-for="(imgObj,index) in imgList" :key="imgObj.uid" class="img-content">
<el-image
:src="imgObj.url"
class="image-row"
:preview-src-list="imgPreview"
></el-image>
<img src="@/assets/img/image_del.png" class="image-close" @click="delImage(index)" />
</div>
</div>
data() {
return {
imgList: [],
imgPreview: []
}
},
methods: {
onImportFileChange(file) {
file.url = URL.createObjectURL(file.raw)
this.imgList.push(file)
this.imgPreview.push(file.url)
},
delImage(index) {
this.$set(this.imgList, this.imgList.splice(index, 1))
this.$set(this.imgPreview, this.imgPreview.splice(index, 1))
}
}
求解,谢谢~
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…