Post 表单数据到 php 使用 axios 的脚本

Post form data to php script using axios

我正在尝试使用 axios 将表单数据发送到 php 脚本。 axios 的语法是否正确? 如何查看通过post方法发送的数据?

我刚开始使用 vuetify 和 php 编程,所以我需要一些帮助

methods: {
      formSubmit(e) {
                e.preventDefault();
                let currentObj = this;
                this.axios.post('http://localhost/index.php/',{
                     name : this.name, user : this.username
                })
                .then(function (response) {
                    currentObj.output = response.data;
                })
                .catch(function (error) {
                    currentObj.output = error;
                });
            },
}

在 php 文件中有:

<?php
require_once 'limonade.php';

$data = $_POST;


dispatch('/api/', 'test1');
function test1()
{
    return 'Hello';
}

run();

您的 php 仅在调用 GET 时起作用,limonade 的 dispatch() 仅用于 GET。

在您的 php 中,您正在 /api/ url 上创建一个 GET 端点,它将执行 test1 函数。这意味着当你通过 get 调用 /api 时,你将得到 Hello 作为答案。

如果你想让它成为 POST(不触及你的 javascript),php 应该是这样的:

 # '/' because you are calling to http://localhost/index.php/ it could be '/whatever' if you call http://localhost/whatever (assuming you have configured everythign as limonade recomends)
function test2()
dispatch_post('/', 'test2'); 
{
    return 'Hello via post';
}