zjxxxxxxxxx / axios-miniprogram Goto Github PK
View Code? Open in Web Editor NEW基于 Promise 的 HTTP 请求库,适用于各大小程序平台。
Home Page: https://axios-miniprogram.com
License: MIT License
基于 Promise 的 HTTP 请求库,适用于各大小程序平台。
Home Page: https://axios-miniprogram.com
License: MIT License
// 更新用户数据
const res = await updateUser(useAuth.userInfo.uuid, data)
useAuth.userInfo!.nickname = res.data.nickname
// 刷新用户Token
const resToken = await refreshTokenApi(params)
发现第二个请求一直报错,检查后是在config.headers 中加上了Authorization,
但是我在请求拦截中做过了判断:
if(useAuth.token.access_token && config.url !== '/sso/sso/token') {
config.headers['Authorization'] = Bearer ${useAuth.token.access_token}
}
发现独立发送刷新Token没问题,但是和其它的同时发送,第二个刷新用户Token的请求中被带上了Authorization,导致失败。
No response
源码包(指直接下载 zip 文件的方式)
我查看了原版axios的仓库明白了这是一个功能,而不是错误。
但还是想问一下如何在axios-miniprogram里让实例继承全局拦截器?
盼回复...
原生微信小程序
参考文档用
npm install -D axios-miniprogram
安装, 再用 [微信开发者工具] -> [工具]-> [构建 npm]
报错 : module 'utils/axios-miniprogram.js' is not defined, require args is 'axios-miniprogram'
小程序根目录中的 miniprogram_npm 目录,也没有 axios-miniprogram 文件夹,说明小程序 构建npm 这步, 没有执行成功, 所以才会报错
解决方案: npm install axios-miniprogram 把命令改成这个就可以了.
npm
微信PC端小程序不支持Object.values()和Object.entries(),微信开发者工具打开es6转es5及增强编译都打开了,也不行。
import axios from "axios-miniprogram";
// 获取轮播图
async getCarouselList(): Promise<CarouselModel[]> {
return this.requestT<CarouselModel[]>('/carousel-list')
}
// 通用请求封装
async requestT<T>(url: string, param?: any): Promise<T> {
return new Promise<T>(async (resolve, reject) => {
let result: undefined | Result<string> = undefined
console.log(`典典sdk提示: platform type is ${this.platform}`)
switch (this._platform) {
case PlatformType.WEB:
//web请求
result = await prequest<Result<string>>(`${this.url}${url}`, {
method: 'GET',
params: param
})
break
case PlatformType.MINI:
//小程序请求
let response = await axios.get<Result<string>>(`${this.url}${url}`, {
params: param
})
result =response.data
}
if (result) {
successResultHandle<string>(result, data => {
resolve(tkDataToObject<T>(data))
}, message => {
console.log(message)
})
}else{
console.log('返回为空')
}
})
}
把请求注释就不会报错
建议将安装后怎么引入该插件也卸载文档中,不然会有点无从下手,难道我要一个个试吗?我还是通过vscode的提示才知道的
此类请求在restful接口设计中常见,且axios存在对应方法。
Ios机有零宽断言问题呀,我尝试注释掉引入的axios,就不会有零宽问题
AxiosResponseData默认应该是any才对吧
在axios库中
export interface AxiosResponse<T = any, D = any> {
data: T;
status: number;
statusText: string;
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
config: InternalAxiosRequestConfig<D>;
request?: any;
}
https://github.com/axios/axios/blob/a989ccdc1a672171e9b45d3f02edc260109a607c/index.d.ts#L378
No response
npm
想在axios的config中增加自定义字段来实现自定义的拦截器插件,
但是发现源代码中有一个priorityFromConfig2Keys,只会传递数组中有的key value,会过滤掉自定义字段。
请问一下能不能加上可以配置自定义字段的选项?
你好,小程序导入 执行完npm 构建 一直提示这个,有遇到过吗?
[Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.
[system] WeChatLib: 2.32.3 (2023.11.20 23:35:17)
Current Wechat version do not support asynchronous getSystemInfo. "wx.getSystemInfoAsync" will be finished by synchronous implementation.
[system] Subpackages: N/A
[system] LazyCodeLoading: true
Lazy code loading is enabled. Only injecting required components.
[Violation] 'setTimeout' handler took 121ms
app.js错误:
Error: module 'kits/fetch/axios-miniprogram.js' is not defined, require args is 'axios-miniprogram'
at q (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at n (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at index.js?t=wechat&s=1700653677994&v=4fb5352f9f01f60d2620d908a5650988:34
at WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1
at f.runWith (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at q (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at n (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at index.js?t=wechat&s=1700653677994&v=22cf6a6c86864f33957ae69f55a37b33:24
at WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1
at f.runWith (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)(env: macOS,mp,1.06.2310080; lib: 2.32.3)
Error: module 'kits/fetch/axios-miniprogram.js' is not defined, require args is 'axios-miniprogram'
at q (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at n (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at index.js?t=wechat&s=1700653677994&v=4fb5352f9f01f60d2620d908a5650988:34
at WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1
at f.runWith (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at q (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at n (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)
at index.js?t=wechat&s=1700653677994&v=22cf6a6c86864f33957ae69f55a37b33:24
at WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1
at f.runWith (WASubContext.js?t=wechat&s=1700653677994&v=2.32.3:1)(env: macOS,mp,1.06.2310080; lib: 2.32.3)
Page "pages/index/index" has not been registered yet.
[system] Launch Time: 6725 ms
yarn
[点个赞 @
有木有方法可以用 FormData 请求的
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.