<!-- demo 上传单个图片-->
<template>
<div>
<h2 style="margin-bottom:10px">上传单个图片</h2>
<el-upload
class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:http-request="httpRequest"
:class="{'demo-httpRequestImg':httpRequestImg}"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisibleImg" append-to-body class="ImgClass">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
</div>
</template>
<script>
export default {
data(){
return{
dialogImageUrl: '',//预览url
dialogVisibleImg:false,
httpRequestImg:false,//展示单个图片
}
},
methods:{
httpRequest(a) { //上传成功
this.httpRequestImg = true;
},
handlePictureCardPreview(file) { //预览
this.dialogImageUrl = file.url;
this.dialogVisibleImg = true;
},
handleRemove(file, fileList) { //删除
this.httpRequestImg = false;
console.log(file, fileList);
},
}
}
</script>
<style lang="scss" scoped>
.demo-httpRequestImg{
/deep/ .el-upload--picture-card{
display: none;
}
}
</style>