@saber2pr/request
v0.1.5
Published
> 提供全局拦截器配置
Downloads
5
Readme
@saber2pr/request
提供全局拦截器配置
为什么?
已经有 axios...
qwq
axios 在使用 rollup 打包时会发生错误,无法处理 http 依赖(别和我说 webpack :(
npm install @saber2pr/request
API
new Request(baseConfig)
常用请求
new Request().get(url, config)
new Request().post(url, config)
new Request().put(url, config)
new Request().delete(url, config)
自定义请求
new Request().fetch
拦截器
- new Request().interceptors
- new Request().interceptors.request
- new Request().interceptors.request.use
- new Request().interceptors.requestInterceptors
- new Request().interceptors.response
- new Request().interceptors.response.use
- new Request().interceptors.responseInterceptors
import axios from "@saber2pr/request" // const axios = new Request()
axios.interceptors.request.use(config => {
/** code **/
config.headers.Authorization =
"Basic " + Base64.encode(`${username}:${password}`)
return config
})
axios.interceptors.response.use(res => {
switch (res.status) {
case 200:
return res
case 401:
push("/login")
break
default:
push("/error")
}
})
还需要说么。。
使用 typescript 编码,不需要文档!qwq
npm start
npm run dev
npm run serve
Author
saber2pr