Apr 22, 2021
0
Level 1
InertiaJS with Axios for sending data
Hello!
I'm currently starting my first project with Inertia (and with Vue).
I want to send some data via Ajax to my Vue, but I'm getting lost with Axios use.
In my controller I made a new method:
public function data()
{
$data = [];
$projects = Projects::get();
foreach($projects as $p){
$data[] = [
$p->name,
$p->priority_id,
$p->responsible_id,
$p->start_date,
$p->alias
];
}
return json_encode(["data" => $data]);
}
But I'm getting lost on how should I do it in my Vue view and in my script part.
Script:
async asyncData(){
const {data} = await axios.get('projects.data', {params: {
projectData: [
{data: 'name'}
{data: 'priority_id}
{data: 'responsible_id}
{data: start_date}
{data: 'alias}
}}
}
I don't know how to call it in my view and if I'm doing correctly.
Thanks in advance!
Please or to participate in this conversation.