【发布时间】:2020-01-03 09:15:56
【问题描述】:
我确信这是一个容易的,希望它很容易。在设置 axios(使用 VUE)并尝试发布任何内容时,没有收到 POST。邮递员工作正常,但我的带有 Axios 的 vue 应用程序没有,POST 数组到达空。
devtools 中的传出请求负载具有变量(目前只是'test'='test。
来自 Vue
this.$axios.post("http://localhost/api/process.php?action=addEntry", {
test:"test"
}).then(function (response) {
alert(JSON.stringify(response));
})
.catch(function (error) {
alert("error");
alert(JSON.stringify(error));
});
return
},
来自 PHP Api - process.php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: User-Agent, Sec-Fetch-Mode, Referer, X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: POST");
header('Content-Type: application/json;charset=UTF-8');
echo (var_dump($_POST['test']));
echo (var_dump($_POST));
输出
POST 不可用。
标题
【问题讨论】:
-
在哪个方法中添加你的axios代码应该是
mounted方法如果是这样尝试在你的组件中导入axios并写axios.post('') -
你能分享你的 .vue 文件吗?我觉得少了点什么!