【发布时间】:2021-05-21 09:16:27
【问题描述】:
这是我关于使用 Svelte/Sapper 的问题
- 我在
/src/routes/login.js中有一个文件 - 根据 Sapper 文档,它将在
http://<my_domain>/login中创建一个 API 端点,它会这样做 - 现在在
login.js,我想调用另一个API服务器,假设它是http://another_server/auth - 无论我如何使用
fetch函数:fetch("http://another_server/auth")、this.fetch("http://another_server/auth"),Svelte 响应:(this.)fetch is not defined。 - 文档说应该在
preload()内运行,所以我把fetch包在export async function preload(){}下,没用
所以我的问题是:除了使用axios,我可以在服务器端API请求中继续使用fetch吗?
刚刚在模板[slug].json.js文件中测试,当我添加(this.)fetch函数时,它没有编译,同样的错误:(this.)fetch is not defined
非常感谢。
【问题讨论】: