【发布时间】:2021-04-28 11:42:14
【问题描述】:
我的服务器(用Django 编写)在http://localhost:8000 运行。
Nuxt 应用程序正在http://localhost:3000 上运行。
当我向服务器发送请求(如http://localhost:8000/api/v1/user/position/)时,firefox 浏览器中出现以下错误。
跨域请求被阻止:同源策略不允许读取 http://localhost:8000/api/v1/user/position/ 的远程资源。 (原因:缺少 CORS 标头“Access-Control-Allow-Origin”)。
火狐:
铬:
以下是我的nuxt.config.js 文件的一部分。
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
axios: {
baseURL: 'http://localhost:8000/api/v1/',
},
我正在发送请求的功能:
async getAllPosition() {
this.loading_position = true;
await this.$axios.get('user/position/').then(response => {
this.position = response.data;
}).finally(() => {
this.loading_position = false;
})
}
我认为是关于代理的,但我不知道如何配置它。
【问题讨论】:
-
这篇文档可以帮到你nuxtjs.org/faq/http-proxy
标签: vue.js cors nuxt.js django-cors-headers