@hal.littel
To send data from a Laravel controller to a Vue.js component, you can use Laravel's Blade templating engine to pass the data to your Vue component as props. Here's a step-by-step guide to achieve this:
1 2 3 4 5 6 |
public function index() { $tasks = Task::all(); return view('tasks.index', ['tasks' => $tasks]); } |
1
|
<tasks-component :tasks="@json($tasks)"></tasks-component> |
1 2 3 4 5 6 7 |
export default { props: ['tasks'], mounted() { console.log(this.tasks); } } |
Now, when your Vue component is mounted, it will have access to the tasks
data passed from the Laravel controller via props. You can then use this data in your Vue component as needed.
That's it! You have successfully sent data from a Laravel controller to a Vue.js component.