当点击上传图片的时候上传图片数量大于1的之后隐藏上传图标
<template>
<el-upload action="#" list-type="picture-card" :auto-upload="false" drag :class="{ disabled: uploadDisabled }"
:file-list="goodsimage" :limit="1" :before-upload="handleBeforeUpload">
<el-icon>
<Plus />
</el-icon>
<template #file="{ file }">
<div>
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
</div>
</template>
</el-upload>
<el-dialog v-model="dialogVisible">
<img :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Plus } from '@element-plus/icons-vue'
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
const goodsimage = ref([]) // 文件以数组的形式存储 已上传图片的数组
const uploadDisabled = ref(false)
// 隐藏图片上传按钮
// const uploadDisabled = () => {
// return this.uploadDisabled = goodsimage.value.length > 0 //判断图片上传的数量动态控制按钮隐藏与显示
// }
const handleBeforeUpload = () => {
if (goodsimage.value.length === 1) {
const uploadBtn = document.querySelector('.disabled') as HTMLElement;
if (uploadBtn) {
uploadBtn.style.display = 'none';
}
}
}
</script>
<style>
.disabled {
display: none;
}
</style>
<!-- :class="{ disabled: uploadDisabled }
类名disabled 依赖于数据uploadDisabled 当其为true的时候,div 会拥有类名 disabled
-->
>
>
>
```javascript
>
```