JS代码
delFileList(index){
let that = this;
that.file.splice(index, 1); console.log(that.file);
}
handleUpload (file) {
let that = this;
if(that.file.length >= 5){
this.$Message.info("最多只能上传5个文件");
}else{
that.file.push(file);
}
return false;
}axios提交方法代码:
upload(){
let that = this;
let _jsid = that.$route.query.id;
if(that.file.length > 0){
that.loading2 = true;
//创建 formData 对象
let formData = new FormData();
//向 formData 对象中添加文件
formData.append('jsid', _jsid); //多个文件上传
for(var i=0; i< that.file.length; i++){
formData.append("uploadFile",that.file[i]); // 文件对象
}
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
axios.post(that.http + "/shweb/gys/gysmsge/gysuploads.action", formData, {
timeout: 10000,
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(function (rdata) {
that.loading2 = false;
if(rdata.data == "0"){
that.islook = false;
that.islookshenghe = true;
}
console.log(rdata);
}).catch(function (error) {
that.loading2 = false;
that.$Message.error('服务器错误' + error);
});
}else{
that.$Message.error("请至少上传一个文件");
}
}










