我的服务器(使用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)。 Chrome: 我看到了这个链接和这个,但我不知道问题出在哪里?
以下是我的
我发送请求的函数是:
我认为这是关于代理的问题,但我不知道如何配置它。
Nuxt应用程序运行在http://localhost:3000。
当我向服务器发送请求(例如http://localhost:8000/api/v1/user/position/),我在firefox浏览器中得到以下错误:
跨域请求被阻止:同源策略不允许读取远程资源http://localhost:8000/api/v1/user/position/。(原因:缺少CORS头Access-Control-Allow-Origin)。 Chrome: 我看到了这个链接和这个,但我不知道问题出在哪里?
以下是我的
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;
})
}
我认为这是关于代理的问题,但我不知道如何配置它。