Coder Social home page Coder Social logo

zjxxxxxxxxx / axios-miniprogram Goto Github PK

View Code? Open in Web Editor NEW
246.0 246.0 14.0 766 KB

基于 Promise 的 HTTP 请求库,适用于各大小程序平台。

Home Page: https://axios-miniprogram.com

License: MIT License

TypeScript 98.69% JavaScript 1.31%
axios mini miniprogram

axios-miniprogram's People

Contributors

zjxxxxxxxxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

axios-miniprogram's Issues

当上下顺序发送请求后,配置中的数据相同

描述错误

// 更新用户数据
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-miniprogram 问题而不是特定于框架的问题。

uniapp h5 打包以后无法请求

描述错误

会提示这个错误Error: [axios-miniprogram]: adapter 不是一个 function

附加上下文

image

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

实例如何继承全局拦截器

我查看了原版axios的仓库明白了这是一个功能,而不是错误。
但还是想问一下如何在axios-miniprogram里让实例继承全局拦截器?
盼回复...

原生微信小程序 解决 module 'utils/axios-miniprogram.js' is not defined, require args is '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 把命令改成这个就可以了.

附加上下文

image

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

微信PC端小程序兼容

微信PC端小程序不支持Object.values()和Object.entries(),微信开发者工具打开es6转es5及增强编译都打开了,也不行。

小程序中无法使用,还是我接入方式不正确

如图
image
在组件中请求接口

    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('返回为空')
            }
            
        })
    }

把请求注释就不会报错

上传文件名为中文时后端怎么还原?

描述错误

如题,后端得到的是编码后的文件名,怎么还原为原文件名?通过Api调试工具测试,后端是正确的中文文件名,故排除了后端的问题。经前端跟踪排查,一直到传入axiox-miniprogram的api,文件名没有被编码,因此问题可能与axiox-miniprogram有关。请问如何解决?

附加上下文

采用的技术栈:vue + taro3 + wechatdevtools

使用过的包管理器

yarn

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

怎么引入

建议将安装后怎么引入该插件也卸载文档中,不然会有点无从下手,难道我要一个个试吗?我还是通过vscode的提示才知道的

请求拦截器中,修改header会导致全局变化

描述错误

比如我在拦截器中添加token,token会被固定在header中,除非我手动删除掉token delete config.headers.token,否则token就一直存在

附加上下文

No response

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

钉钉小程序中真机预览报无权跨域调用

描述错误

钉钉中真机预览及上传后预览,报错,无权跨域调用,对应的接口已经在安全中心配置过了,使原生请求不会出现这个错误

附加上下文

image

测试了使用原生请求及其他库,没有这个错误,真机可以正常预览

使用过的包管理器

yarn

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

AxiosResponseData默认应该是any才对吧

描述错误

AxiosResponseData默认应该是any才对吧
image
在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-miniprogram 问题而不是特定于框架的问题。

自定义config headers丢失

描述错误

2.3.1 中,自定义config headers丢失

附加上下文

没看懂为啥要delete config header
微信截图_20230423131318

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

不能在axios的config中增加自定义字段

想在axios的config中增加自定义字段来实现自定义的拦截器插件,
但是发现源代码中有一个priorityFromConfig2Keys,只会传递数组中有的key value,会过滤掉自定义字段。
请问一下能不能加上可以配置自定义字段的选项?

小程序导入 执行完npm 构建 一直提示这个,Error: module 'xxx/xxx/axios-miniprogram.js' is not defined, require args is 'axios-miniprogram'

描述错误

你好,小程序导入 执行完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

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

uni-app 即将不再内部支持!

清晰简洁的问题描述

由于第三方框架的版本更新存在导致该库无法运行的情况,自 2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除。

建议的解决方案

您依然可以使用自定义适配器兼容 uni-app,适配器如何使用可以参阅文档。

选择

No response

附加上下文

No response

验证

能否支持最新的axios

清晰简洁的问题描述

目前responseType: "stream",的时候,不能像axios1.4.0 以后,onDownloadProgress:这个方法不走。最新的axios是走onDownloadProgress的

建议的解决方案

希望能支持最新的axios

选择

No response

附加上下文

No response

验证

文件上传乱码与返回格式问题

描述错误

  1. 上传文件返回值出现乱码现象
image 2. 上传成功后的data没有被序列化成json

image

附加上下文

image

使用过的包管理器

yarn

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

post 无法使用formData入参

描述错误

post 请求无法使用formData入参,参数总是为空对象

附加上下文

No response

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

不要去掉url的斜线

描述错误

请求url不需要斜线的话应该使用者自己删吧,不应该axios-miniprogram来删。比如我们的其他接口不需要斜线,但是登录接口需要斜线,这个斜线应该使用者来处理才对吧

附加上下文

image
image

使用过的包管理器

npm

验证

  • 遵守我们的行为准则
  • 阅读贡献指南.
  • 阅读文档.
  • 检查是否还没有报告相同错误的问题以避免创建重复。
  • 确保这是 axios-miniprogram 问题而不是特定于框架的问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.