首页 > 解决方案 > 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/');

我没有问题!为什么?

标签: typescriptproxynuxt.js

解决方案


推荐阅读