【发布时间】:2021-10-23 04:39:45
【问题描述】:
我正在尝试通过 nuxt axios 向 Localhost API 发出一个简单的请求,但是,无论我在 nuxt 配置文件中尝试做什么,它总是会出现此错误:
访问 XMLHttpRequest 在 'https://localhost:44309/api/api/usuarios/login' 来自原点 “http://localhost:3000”已被 CORS 策略阻止:响应 预检请求未通过访问控制检查:否 请求中存在“Access-Control-Allow-Origin”标头 资源。
我提出这样的要求:
const data= await this.$axios.$post(
'https://localhost:44309/api/usuarios/login',
loginObject
)
这是我的 nuxt.config.js:
publicRuntimeConfig: {
axios: {
baseURL: 'https://localhost:44309/api'
}
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
proxy: true,
baseUrl: 'https://localhost:44309/api',
proxyHeaders: false,
credentials: false
},
proxy: {
'/api/': { target: 'https://localhost:44309/api', pathRewrite: { '^/api/': '' }, changeOrigin: true }
}
如您所见,我已经尝试了 n 件事,但没有任何效果,我不再明白了。在我的 .NET webApi 服务器上,我已经在配置中添加了 services.Cors(),没有任何效果。
【问题讨论】:
标签: vue.js http asp.net-web-api axios nuxt.js