0.0.6 • Published 2 years ago
xyq-req v0.0.6
xyq-req
基于axios的网络请求封装,统一网络请求交互
例子: 服务端返回数据格式
{
"code":0, // 状态码; 0为success,其他为fail
"message":"错误信息", // 错误信息
"data":{} // 业务数据
}
- 请求后,正常网络请求 && code === 0,会 resolve会返回 ,返回内容为 data内容
- 其他情况 均会 reject 返回 Error对象
安装方式
yarn
yarn add xyq-req
npm
npm install xyq-req
使用方法
import {get,post,setConfig} from 'xyq-req';
setConfig({
baseURL:'https://test-saas.orionstar.com',
showLog:true,
// responseFormatList:[ // 映射服务端返回字段,可以映射多组,按顺序判断解析
// {
// "code":"ret", // 状态码
// "message":"msg", // 错误消息
// "data":"data", // 数据
// "successCode":0,
// },
// ],
publicParams:()=>{ // 网络请求的公共参数
return {
pf: 'h5',
ctime: Math.floor(Date.now() / 1000),
};
}
});
get('/robotapi/jiedai/health_code_list',{}).then(res=>{
console.log('成功返回,直接使用数据',res);
}).catch(e=>{
console.log('返回错误',e);
})