我正在尝试在 React chrome 扩展模块中使用 axios,但我遇到了这个问题。
未捕获(承诺中)错误:错误:适配器“http”在构建中不可用
// background.ts
import axios from "axios"
...
axios.get<SerInyResponse>("https://realtor.p.rapidapi.com/locations/v2/auto-complete")
.then(response => {
this.Storage.setLocalStorage(response.data).then( (re) => {
resolve(response.data.Listeners)
})
})
.catch( err => {
reject(new Error(err))
})
有人可以帮助我吗?
用 Fetch 写入
const res = await fetch(url, { method: "GET", credentials: "include", headers: { Cookie: token }, });
Service Worker 仅支持 fetch
因为中间件仅支持 fetch,所以基于
http
模块的 axios 在边缘运行时不支持。目前唯一的办法就是使用fetch,或者尝试xior
,基于fetch,类似axios API,插件支持,非常精简的大小,支持bun/deno/vite/react/expo/react-native等: