When using VueJS, how do you pass a prop to a child component from the $root
view instance when 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>
Looking through the vue-router documentation, there is a method of passing a prop via the url. However that makes the prop stateless, and doesn't retain reactivity. It only updates the prop on page refresh.
Passing a static prop leaves me with the same problem.
How can I pass a prop to the child while still retaining reactivity for the prop?