在楼上的方法中,问题已经决定了,其实axios已经提供了方法。
贴上我自己的代码看看吧。
用data声明source
数据()。
返回{
source :空,//取消上传
}
//上传文件
let that=this;
letcanceltoken=that.axios.cancel token; //Axios让我修改了axios原型链。
that.source=cancelToken.source (;
var fd=new FormData (; 声明格式数据()
FD.append('image ',that.$refs.upload.files[0] );
FD.append('filename ',that.formData.images );
FD.append(system_type ),that.formData.systemTypeVal );
FD.append('name ',that.formData.imagesName );
FD.append('description ',that.formData.description );
FD.append(system_vision ),that.formData.systemVersion );
FD.append(disk_format ),that.formData.format );
发送that.axios(//axios请求
方法: '开机自检',
URL : that.prefix '/yr _ images/create _ image/',
数据:软盘,
headers : { ' content-type ' : ' multipart/form-data ' },
cancel token : that.source.token,//取消事件
上传onuploadprogress (进度事件)//进度条事件
进度事件.长度计算(if ) {
letval=(progress event.loaded/progress event.total * 100 ).tofixed(0);
that.formdata.show progress=true;
that.formdata.start value=parseint (val )
}
}
() )
. then (功能(响应) {
if(response.data.status==1) {
if (that.formdata.start value==100 ) {
util.notification('success ','成功',response.data.success_msg ); //这是全球打包的方法,所以不用在意。
that.getdata(1;
}
} else {
util.notification('error ','错误',response.data.error_msg );
}
that.modal.formVisible=false;
() )
. catch (功能(错误) {
that.modal.loading=false;
that.modal.formVisible=false;
if(that.axios.iscancel(error ) )//主要在此
util.notification('success ','成功','上载解除操作成功');
}
);
}
//单击取消事件,即上图中的取消按钮
cancel () }
let that=this;
if(that.source )//我先判断soucre是否存在。 打开弹框什么也不操作,点击取消按钮如果没有该层的判断,that.source.cancel ('取消上传'); 报告错误。
that.source.cancel ('取消上传); //“上载解除”一词由上面catch ()的error输出,请在控制台上查看。
}
that.modal.formVisible=false;
}