axios upload files
Package axios
On demand write the corresponding js
Mine is the financial piece, in order to facilitate Look, I deleted the other functions
/**
* finance模块接口列表
*/
import axios from "./http"; // 导入http中创建的axios实例
import qs from "qs"; // 根据需求是否导入qs模块
import path from "../apiPath";
const finance = {
cashUpdate(file, config) {
return axios.post(path.cash_update, file, config);
}
};
export default finance;
Use the page's needs
//
let formData = new FormData();
let file = this.files[0];
formData.append("file", file);
this.$api.finance
.cashUpdate(formData, {
headers: { "Content-Type": "multipart/form-data" }
})
.then(response => {
console.log(res);
})
.catch(() => {});
Reference this article https://blog.csdn.net/liningaa/article/details/70573354