Axios到php api-POST表单为空

Axios到php api-POST表单为空,php,post,axios,Php,Post,Axios,我相信这很容易,希望很容易。在设置axios(使用VUE)并尝试发布某些内容或任何内容时,不会收到post。Postman工作正常,我的vue应用程序和Axios不工作,POST数组为空 devtools中的传出请求有效负载具有变量(目前只有'test'='test) 来自Vue this.$axios.post("http://localhost/api/process.php?action=addEntry", { test:"test" }).the

我相信这很容易,希望很容易。在设置axios(使用VUE)并尝试发布某些内容或任何内容时,不会收到post。Postman工作正常,我的vue应用程序和Axios不工作,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
    },
来自phpapi-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));
输出

该职位不可用

反应

标题

试试这个

axios.post("urlapi", 
                 data: {
                    foo: 'bar', // This is the body part
                  }, {
                headers: {
                    'Content-Type': 'application/json'
                }
            }).then(function(res){
                console.log(res);
            }).catch();

这对我很有用。

在哪种方法中,您可以添加您的Axios代码?如果是,请尝试在组件中导入Axios并编写
Axios.post(“”)
您可以共享您的.vue文件吗?我想缺少了一些东西!