We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
能否提供一下全局拦截的例子?
The text was updated successfully, but these errors were encountered:
为所有的默认请求注入一个认证的 Authorization
import { REQUEST, transformRequestSendDefault } from "miniprogram-network"; // 同步方式 REQUEST.Defaults.transformSend = (options) => { options.headers["Authorization"] = `brearer ${getAuthToken()}`; // 更安全的做法应该检查一下 headers 是否存在 return transformRequestSendDefault(options); // 剩下数据使用默认转换转换成wx.request的标准格式 }; // 异步方式 (promise 也可) REQUEST.Defaults.transformSend = async (options) => { const token = await getAuthTokenPromise(); // 异步方法 options.headers["Authorization"] = `brearer ${token}`; return transformRequestSendDefault(options); };
Sorry, something went wrong.
No branches or pull requests
能否提供一下全局拦截的例子?
The text was updated successfully, but these errors were encountered: