前端最简洁的接口复用办法节省好多时间,不用用一次写一次
1. 在utils文件夹中新建api.js里面写所有的接口
import {http} from './http'
export const fileUpload = (file, path) => {
return http.post("/app/file/upload", { file, path }, { headers: { "Content-Type": "multipart/form-data" } })
}
2. 在页面中引用
import {fileUpload} from "../../utils/api"
beforeUpload(file) {
return new Promise(async (resolve, reject) => {
this.isUploading = true;
const { uploadPath } = await fileUpload(file, file.name.split(".")[0] + Date.now() + parseInt(Math.random()*50000));
this.filePath = uploadPath;
this.form.setFieldsValue({ name: file.name })
this.isUploading = false;
this.step = 2;
reject("success")
})
},
3. 鼠标移上去展示(哪个页面用到就引入使用)
