el-upload图片上传(上传一张之后按钮隐藏,照片删除按钮出现)
作者:互联网
直接上代码
<template>
<!--el-upload里面绑定一个占位class:设置隐藏-->
<div class="hello">
<el-upload
ref="pictureUpload"
action="#"
list-type="picture-card"
:auto-upload="false"
:class="{ hide: hideUpload }"
:on-change="handleChange"
>
<i slot="default" class="el-icon-plus" />
<div slot="file" slot-scope="{ file }">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
<span class="el-upload-list__item-actions">
<span
class="el-upload-list__item-preview"
@click="handlePictureCardPreview(file)"
>
<i class="el-icon-zoom-in" />
</span>
<span
v-if="!disabled"
class="el-upload-list__item-delete"
@click="fileRemove(file)"
>
<i class="el-icon-delete" />
</span>
</span>
</div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
</div>
</template>
<script>
export default {
name: 'Example',
data() {
return {
// 初始值:hideUpload: false,
hideUpload: false,
dialogImageUrl: '',
dialogVisible: false,
disabled: false
}
},
methods: {
// onChange 对应的处理函数
handleChange(file, fileList) {
console.log('333')
// >=限制的数量,可以使任意值
this.hideUpload = true
},
fileRemove(file) {
this.$refs.pictureUpload.uploadFiles = []
this.hideUpload = false
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
},
}
}
</script>
<style scoped >
.hello >>> .hide .el-upload--picture-card {
display: none;
}
</style>
标签:el,false,hideUpload,true,dialogVisible,file,按钮,上传 来源: https://blog.csdn.net/qq_46193186/article/details/119281273