我正在尝试使用Vue 2.0和axios,并遇到了一些问题。当我尝试使用axios向我的post.php文件发送POST请求时,$_POST数组总是为空。
Post函数:
doPost: function() {
console.log("post in progress")
axios.post('api/post.php', {
title: 'foo',
body: 'bar',
userId: 1
})
.then(response => {
console.log(response)
console.log(response.data)
this.filter = response.data
})
.catch(e => {
this.errors.push(e)
})
}
post.php
<?php
header('Content-Type: application/x-www-form-urlencoded');
echo json_encode($_POST);
?>
请求返回状态码为200,但返回了空对象"[]"。
注意:当我将post的端点更改为jsonplaceholder工具时,它可以正常工作。