request-func
v1.0.0
Published
基于 axios 库封装的请求工具
Downloads
1
Readme
Usage
安装
npm install --save request-func
配置
import request from 'request-func'
const userAPI = {
getUser: `GET /api/users/userInfo`
};
// 或者
const gatherAPI = {
allCvts: `GET /api/cvts`,
getById: ({ id }) => `GET /api/task/${id}`,
task: {
create: "POST /api/task",
getById: ({ id }) => `PUT /api/task/${id}`
},
summary: {
create: "POST /api/meetingMinutes",
update: ({ id }) => `PUT /api/meetingMinutes/${id}`,
}
};
const apis = request(gatherAPI);
apis.allCvts({ params: {} }).then(res => {}).catch(err => {})
apis.task.getById({ id, params: {} }).then(res => {}).catch(err => {})
apis.task.create({ data: {} }).then(res => {}).catch(err => {})
apis.summary.update({ id }).then(res => {}).catch(err => {})
axios 全局设置 http://www.axios-js.com/zh-cn/docs/
import request from 'request-func'
request.axiosConfigs = {
headers: { "X-Requested-With": "XMLHttpRequest" }
};