1👍
✅
I see two ways to do it…
- Add default slot into
TheTopBar
template at the place you wanna see your actions - Remove
TheTopBar
component from your top-level component, place it inside your "main view" components templates (each of them) and define content of the slot there (actions)
Other way could be using Vue router’s Named Views but that would require you to create separate "actions" component for each corresponding "main view" component
Edit
Actually there is other way. portal-vue allows exactly what you want….
0👍
The short answer is no, you cannot inject code from one component to another. You will have to have the template logic inside the header
component.
However, there are a couple of things you can do.
- Inside the
header
component you can check what the current path is withthis.$route.path
. And based on that display the action item. (if you are using a router) - Use a
vuex
store to track what the action item in the header should be. You could have themain
component set the store value andheader
can then read it and act accordingly
I hope this answers your question.
Source:stackexchange.com