<el-upload class="upload-demo" :auto-upload="false" action="" :show-file-list="false" :on-change="handleImport" :limit="3">
<el-button type="primary">导入线索</el-button>
</el-upload>
handleImport(file,fileList) {
if (fileList.length > 1) {
fileList.splice(0, 1);
}
let formdata = new FormData();
formdata.append("file", file.raw);
formdata.append("distributorId", this.distributorId);
var url = "/buyCusDis/buyCarInputExcel";
var config = {
headers:{
"Content-Type": "multipart/form-data"
}
}
this.$post2(url, formdata,config).then(res => {
if(res.code == "0"){
this.$message.success(res.message);
}else{
this.$message.error(res.message);
}
})
},
参考资料:
http://www.imooc.com/wenda/detail/516081
<el-upload :on-change="fileChange" ></el-upload>
data(){
files:[],//要上传的文件对象
},
methods:{
fileChange(file){
this.files.push(file.raw);//上传文件变化时将文件对象push进files数组
},
upload(){
let formData = new FormData();
formData.append('files',this.files);
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
};
axios.post(uploadUrl,formData,config).then(res=>{
if(res.code===0){
this.submitForm();//提交表单
}
})
}
}
网友评论