当前位置: 代码迷 >> 综合 >> Vue Element Upload 组件自定义上传后不再触发上传成功或失败回调
  详细解决方案

Vue Element Upload 组件自定义上传后不再触发上传成功或失败回调

热度:32   发布时间:2023-12-06 21:01:37.0

template部分

<el-uploadaction="fileuPload"list-type="listFile":http-request="uploadFile":on-success="handleUploadSuccess":on-error="handleUploadError">
</el-upload>

script部分

methods: {uploadFile (file) {this.axios.post(file)//上传文件.then(response=>{file.onSuccess(response)}).catch(({err}) => {file.onError(err)})   })},handleUploadSuccess(response, file, fileList) {//文件上传成功后的操作console.log('文件上传成功')},handleUploadError(err, file, fileList){//文件上传失败后的操作console.log('文件上传成功')}}

说明

自定义上传后,成功和失败需要在自定义上传代码中触发。在组件部分需要写文件上传或失败的回调信息(:on-success="handleUploadSuccess" :on-error="handleUploadError"),同时在自定义上传函数中需要手动触发onSuccess,onError

  相关解决方案