发送POST请求到Laravel web.php路由



我有一个简单的Vue应用程序,我在其中发送POST请求与选项(表过滤变量)到后端。我希望能够解构对象并在Laravel 8的TestController中调试它,所以我想通过URL将选项发送给web.php,而不是api.php。因为options是一个对象,所以我不能直接把它放到URL中。

最终我希望能够在浏览器中预览我的Laravel响应,所以我知道它从服务器返回正确的数据。

那么我怎么才能做到这一点呢?

在Vue FormComponent<form @submit="formSubmit">和script

function formSubmit(e) {
e.preventDefault();
let currentObj = this;
axios.post('/formSubmit', {
name: this.name,
description: this.description
}).then(function(response) {
currentObj.output = response.data;
console.log(currentObj);
}).catch(function(error) {
currentObj.output = error;
});
}

首先,为请求创建POST路由。然后只需向这个路由url发出POST请求,并将您的POST参数(您的对象)放入请求体。您可以使用Axios作为示例

let filterOptions = {...};
axios.post(url, filterOptions).then().catch();
你的请求的响应可以在浏览器开发控制台的网络选项卡 中看到

最新更新