鍍金池/ 問答/HTML/ element-ui 的upload組件,before-upload驗證不通過后

element-ui 的upload組件,before-upload驗證不通過后為什么會觸發(fā)了on-remove的執(zhí)行?

"vue": "^2.5.2",
"element-ui": "^2.2.1",

<el-upload
    action="http://mt.cn:3355/backend/config/uploadImg"
    list-type="picture-card"
    :file-list="themePictures"
    :data="themeData"
    :on-success="themeSuccess"
    :on-remove.self="removeTheme"
    :on-error="uploadError"
    :before-upload="beforeUpload">
    <i class="el-icon-plus"></i>
</el-upload>
removeTheme(file, fileList) {
    req_removeTheme({id:file.id}).then(res => {
        this.$message.success('刪除成功')
    })
},
beforeUpload(file) {
    const isMatch = file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png' || file.type === 'image/gif' || file.type === 'image/bmp'
    const isLt2M = file.size / 1024 / 1024 < 1

    if (!isMatch) {
        this.$message.error('圖片格式不匹配')
    }
    if (!isLt2M) {
        this.$message.error('上傳頭像圖片大小不能超過 1MB!')
    }
    return isMatch && isLt2M
},
回答
編輯回答
心沉

好像新的才會出現(xiàn)這個問題,試了下可以通過file.status的狀態(tài)來區(qū)分
`handleRemove(file, fileList) {

  if (file && file.status==="success") {
      //刪除
  }

}`

2018年8月24日 06:55
編輯回答
笨笨噠
   在before-remove事件里面加上 添加成功類型的的判斷,如果你有上傳成功的文件,可以刪除
   如果沒有 就不會彈這個框了
    beforeRemoveFile(file, fileList) {
        const isXLS = file.name.split('.')[1] === 'xls' || file.name.split('.')[1] === 'xlsx';
        if(isXLS){
            return this.$confirm(`確定移除 ${ file.name }?`);
        }
    },
2018年2月23日 06:52