typescript - Nuxt.js 中的代理路由
问题描述
请帮我!我使用Nuxt.js 框架,并且在nuxt.config.ts中有这个配置:
... // some code here
,
axios: {
proxy: true
},
proxy: {
"/api": {
target: "https://example.com" // this is a fictional address
}
}
然后,当我尝试获取一些 JSON 数据(在本地服务器上)时,例如:
this.axios.get('http://localhost:3000/api/my-json');
我有这个问题:
从源“ http://localhost:3000 ”访问“ https://example.com/api/my-json/ ”处的 XMLHttpRequest(从“ http://localhost:3000/api/my-json ”重定向)已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。
/
但是当我在地址末尾添加斜杠字符(“ ”)时,例如:
this.axios.get('http://localhost:3000/api/my-json/');
我没有问题!为什么?
解决方案
推荐阅读
- xml - 如何在 XSLT 遗留代码库中查找死代码
- android - 我无法在暂停的地方恢复我的音频
- azure - AKS 上的 Kubernetes + Docker 容器 pod 阻塞外部端点
- xamarin.forms - 升级到 Xamarin.Forms 4.2 后 Xamarin.Android 崩溃
- git - 如何正确更新 git 子树
- c# - 在“添加新项目”窗口中找不到 SpecFlow 功能文件选项 - VS20019
- html - 如何在SQL中实现字符串whitin
- python - 删除 QTableWidget 单元格中的空间
- view - 如何引用自己的视图
- android - 可以把ndk.dir设置出sdk.dir路径,为什么没有ndk.dir自动创建?