<el-upload
class="upload-demo"
action="#"
multiple
:auto-upload="false"
list-type="picture-card"
:file-list="modelForm.fileList"
:show-file-list="false"
:limit="3"
:on-change="handleChange"
>
<el-button size="small" type="primary">点击上传文件</el-button>
</el-upload>
// 文件状态改变时
handleChange(file) {
let { name , uid } = file
// 利用findIndex方法查询名字是否重复,不重复返回-1
const findCommonNameIndex = this.modelForm.fileList.findIndex(
item => item.name == name
)
// 如果重复则findCommonNameIndex为-1,进去判断进行相应操作
if (findCommonNameIndex !== -1) {
this.$message.warning('不能上传同名的文件')
const selectFileList = this.modelForm.fileList.filter(item => {
return item.uid != uid
})
this.modelForm.fileList = selectFileList
return
}
}
Vue 使用 ElementUi el-upload 手动上传文件限制同名文件
最新推荐文章于 2025-02-10 18:34:25 发布