Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

咨询一下底层请求方法 #60

Open
5 tasks done
freshBirdA opened this issue May 28, 2024 · 4 comments
Open
5 tasks done

咨询一下底层请求方法 #60

freshBirdA opened this issue May 28, 2024 · 4 comments

Comments

@freshBirdA
Copy link

描述错误

我在飞书小程序项目中hook了tt.request方法进行劫持,但是发现使用axios发出的请求无法被我hook的tt.request劫持到。但是我看源码其实原理也是用tt.request去发请求的,所以想请问一下为什么?
代码如下
`export const RequestWithPerformanceReport = ({
reportClient,
}: {
reportClient: any;
}) => {
if (!tt || !tt.request) return;

const originttRequest = tt.request;

tt.request = (options: any) => {
console.log("options:", options)
originttRequest(options);
};
};
`

附加上下文

No response

使用过的包管理器

npm

验证

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

猜测和执行顺序有关,可以尝试在hook后进行手动适配,看看能不能解决问题。

@freshBirdA
Copy link
Author

猜测和执行顺序有关,可以尝试在hook后进行手动适配,看看能不能解决问题。

所以底层应该还是用的tt.request吧(飞书的容器下),另外请问下你说的手动适配是要怎么做呢

@zjxxxxxxxxx
Copy link
Owner

可以参考适配方法

import axios from 'axios-miniprogram';
// 需要确保在hook之后执行
axios.defaults.adapter = axios.createAdapter(tt);

@freshBirdA
Copy link
Author

可以参考适配方法

import axios from 'axios-miniprogram';
// 需要确保在hook之后执行
axios.defaults.adapter = axios.createAdapter(tt);

感谢,好像确实有用,不过需要这样写才行,否则会报错
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants