I have two components :
- Page.vue
- Component.vue
In my Laravel route I do
return inertia('Page', [ 'foo' => Model::all()->map(...) ]);
In Page I do:
<template>
<Component/>
</template>
<script setup>
defineProps({ foo: Array });
</script>
Would it be possible to access foo
, without transiting by Page
? When using nested components. It looks cumbersome to always forward props like <Component :foo='foo'>
.
In this case, only Component
use foo
which is not directly used in Page
.
2
Answers
This video on Laracasts is a great starting point for your topic https://laracasts.com/episodes/2404
You can share a prop data to a subcomponent this way:
Route:
1st component (
Page.vue
) – Here you pass in the data to the subcomponent:2nd component (
Component.vue
) – And here you retrieve it: