Json 通过laravel vue中的axios post发送对象数组
我正在使用vue和laravel。我在console.log(array\u of_obj)中得到了如下对象数组: 每个对象都包含所需的行数据。现在我想通过axios post请求将其发送到Laravel控制器。我该怎么做? 我试过这样做:Json 通过laravel vue中的axios post发送对象数组,json,laravel,vue.js,post,axios,Json,Laravel,Vue.js,Post,Axios,我正在使用vue和laravel。我在console.log(array\u of_obj)中得到了如下对象数组: 每个对象都包含所需的行数据。现在我想通过axios post请求将其发送到Laravel控制器。我该怎么做? 我试过这样做: let json=JSON.stringify(array_of_obj); let post_data={json_data:json} store.dispatch('employees/EmployeeListDownloadPdf', post_d
let json=JSON.stringify(array_of_obj);
let post_data={json_data:json}
store.dispatch('employees/EmployeeListDownloadPdf', post_data).catch(err => { console.error(err) })
在我的vuex部分:
EmployeeListDownloadPdf(ctx, employeeList) {
return new Promise((resolve, reject) => {
axios({
url: '/api/employees/employeeListData',employeeList,
method: 'POST',
})
//.then(response => resolve(response))
.then((response) => {
//console.log(response.data)
});
//.catch(error => reject(error))
})
},
但在我的控制器中,我尝试了以下代码,但得到了空数组
dd(json_decode($request->all(),true));
dd(json_decode($request,true));
我想将所有数据输入控制器,但现在无法访问它们。如何执行此操作?您使用的axios()
不正确:如果您不正确,则需要将员工列表
指定给对象中的数据属性,即:
axios({
url: '/api/employees/employeeListData',
data: employeeList,
method: 'POST'
})
我认为您需要向我们展示VueX action
employees/EmployeeListDownloadPdf
的功能。您共享的内容不显示VueJS应用程序如何将数据发送到服务器。请立即更新。请检查,现在我可以在控制器中获取数据。谢谢。
axios({
url: '/api/employees/employeeListData',
data: employeeList,
method: 'POST'
})