@chenkaixuan000912/uni-app-request
v1.2.4
Published
对uni-app的uni-request与uni-addInterceptor API进行二次封装
Downloads
15
Maintainers
Readme
uniapp-request
对uni-app的uni-request与uni-addInterceptor API进行二次封装
PS:第一次在npm上上传包,可能有很多瑕疵,请谅解
github地址:https://github.com/1305195660/uniapp-request
安装:
npm i @chenkaixuan000912/uni-app-request
使用:
import Request from '@/utils/@chenkaixuan000912/uni-app-request/index.js' // 下载的插件
// import Request from '@chenkaixuan000912/uni-app-request' // 使用npm
代码示例:
import Request from '@chenkaixuan000912/uni-app-request'
uniHttp.setBase({
baseUrl:'https://xxx',
timeOut:5000,
headers:{'Authorization':'xxxx'}
})
const httpRequest = uniHttp.setInterceptor((res:any)=>{
请求成功的后的数据在此进行统一处理,默认返回res.data,如果有需要更改,请前往源码处更改
console.log(res,'请求成功')
},(res:any)=>{
请求失败的后的数据在此进行统一处理,如token失效,权限不够等等
console.log(res,'请求失败')
},(err:any)=>{
发送请求失败的后的数据在此进行统一处理,如:网络错误,地址错了等等
console.log(err,'请求网络错误')
})
export default httpRequest
在组件中使用示例:
const res = await httpRequest({
method:'GET',
url:'/member/profile'
})
console.log(res)