How can VueJS pass a prop to a child component from the $root
view instance while using vue-router
?
$root instance:
const router = new VueRouter({
routes: [{
path: "/dashboard",
component: () => import("./User/Dashboard.vue" /* webpackChunkName: "js/components/user/Dashboard" */ )
}]
});
var app = new Vue({
el: '#app',
router,
data: () => ({
passedProp
}),
});
Laravel Layout using :
@section('content')
<transition name="slide">
<router-view></router-view>
</transition>
@endsection
Child Component served by vue-router:
<script>
export default {
props: [
'clearFormProp'
]
}
</script>
In the vue-router documentation, there is a way to pass a prop via the url, however, this method makes the prop stateless and does not retain reactivity. It only updates the prop on page refresh.
Passing a static prop presents the same issue.
Is there a way to pass a prop to the child component while still maintaining reactivity for the prop?