写在before-update(){}钩子函数里虽然不会调用上传文件的接口,但是会出现在文件列表里
解决方案就是写在fileChange(){}钩子函数里。
// 文件状态改变时的钩子
fileChange(file, fileList) {
this.hideUpload = fileList.length >= this.limitNum
this.fileList.push(file.raw)
// 解决上传文件之前钩子钩子函数无效
const extension = file.name.substring(file.name.lastIndexOf('.') + 1)
if (extension !== 'xlsx' && extension !== 'xls') {
this.$message.warning('只能上传后缀是 .xlsx 或 .xls 的文件')
return false
}
},