-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Aniu edited this page Feb 7, 2020
·
17 revisions
欢迎来到 nuomi-request wiki!
nuomi-request是基于 axios 封装的请求库,目的是为了方便接口的复用和维护,内置了mock功能可以在开发阶段进行模拟测试。
yarn add nuomi-request
npm i --save nuomi-request
import { createRequests } from 'nuomi-request';
const requests = createRequests({
getList: '/path/getList:get',
save: '/path/save:post',
}, {
getList: {
data: [{ id: '1' }, { id: '2' }],
message: 'ok',
},
save: ({ content }) => {
if (content) {
return {
data: {},
message: 'ok',
}
}
return {
data: {},
message: 'error',
}
},
});
requests.getList().then(({ data }) => {
console.log(data.data); // [{ id: '1' }, { id: '2' }]
});
requests.save({ content: '' }).then(({ data }) => {
console.log(data.message); // error
});