TL;DR: Is it possible to pass content to a specific slot of a component referenced in the parent component, from the child component?
I'm using the Vue Webpack Template which comes with Vue Router which provides the basis of a Single Page Application out of the box.
The issue I'm facing, is that I have a master layout, simplified below:
<template>
<div id="app">
<Nav/>
<APageWithDifferentNav/>
</div>
</template>
<script>
import Home from "./components/views/Home";
import APageWithDifferentNav from "./components/views/APageWithDifferentNav";
import Nav from "./components/Nav";
export default {
name: "App",
components: {
Nav, Home, APageWithDifferentNav
}
};
</script>
And the nav component something like this:
<template>
<div class="nav">
<ul class="nav__list">
<li class="nav__list-item">always show this nav item</li>
</ul>
<slot>
<ul class="nav__list replace-this">
<li class="nav__list-item">only show this</li>
<li class="nav__list-item">if no slot</li>
<li class="nav__list-item">content provided</li>
</ul>
</slot>
</div>
</template>
<script>
export default {
name: "Nav"
};
</script>
I want to be able to change a slot inside the Nav
component, from within a view component.
For example, on a checkout or onboarding flow, you want to limit the navigation options shown to the user, and swap in other content to highlight where they are on their journey.
Is there a way for me to do this, without having to move <Nav/>
inside every single page's template?
I've put together a more indepth code example to show what I'm after which you can view here.
Any help is much appreciated.