【发布时间】:2021-12-07 01:23:04
【问题描述】:
我是 laravel-nova 和 vuejs 的新手。我正在向我的private-api swagger 发送请求。我已经尽我所能。我更改了mozailla documentation on cors 此处给出的 apache 服务器的 conf 文件。我试过放
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
在发送请求时。它不起作用。这是我在 laravel-nova Vue 工具中的 vue 代码。
<script>
import VueButtonSpinner from 'vue-button-spinner';
export default {
components: {
VueButtonSpinner
},
data() {
return {
showTable: false,
token_utente: "7e407066-1c6a-11ec-9bbe-0aae38056063",
encoding: "na",
document_type: "na",
indirizzo: "na",
toponimo: "na",
via: "na",
comune_registro: "na",
cap: "na",
provincia_registro: "na",
codice_fiscale: "na",
partita_iva: "na",
ccia: "na",
nrea: "na",
};
},
metaInfo() {
return {
title: 'RegistroImprese',
}
},
mounted() {
//
},
methods: {
onSubmit() {
this.isLoading = true
let param = {};
param = {
'token_utente': this.token_utente,
'codici_servizi': [ this.codici_servizi ],
'document_type': this.document_type,
'encoding': this.encoding,
'partita_iva' : this.partita_iva,
'ccia' : this.ccia,
'nrea' : this.nrea,
'solo_sedi' : this.solo_sedi,
'escludi_cessate' : this.escludi_cessate,
}
Nova.request().post('my-private-api', param).then(response =>
{
this.data = response.data;
this.isLoading = false;
this.status = true;
setTimeout(() =>
{
this.status = ''
}, 2000);
}).catch(error =>
{
console.error(error)
this.isLoading = false
this.status = false //or error
})
},
}
}
</script>
【问题讨论】:
-
“我试过推杆”——这没有意义。 Access-Control-Allow-Origin 应该在服务器端添加,它在客户端没有意义,因为客户端无法控制它。问题还是应该在服务器端解决
-
我也是这么想的。当我尝试 curl 我的 API 时,响应是 HTTP/2 404。你能告诉我一些关于这个的事情吗?
标签: laravel cors laravel-nova