I have layout like this:
.------------------------+----------------.
| Current Tab Title | Controls |
+------------------------+----------------+
| Tab1 Tab2 [Tab3] |
+-----------------------------------------+
| Main Content |
| |
'-----------------------------------------'
The "Controls" field contents should logically belong to the current tab. But I cannot put it in the same Vue component because it should be rendered in the different place of application template. Also, tab title should depend on the current tab chosen.
I made Tab1
etc a <router-link>
components.
For Current Tab Title
I abused the $route.name
field.
I can use named views to display Controls
.
But I cannot understand how to have some controls in Controls
block which would depend on and influence the state in current tab.
For example, for Tab1
we want to display a checkbox which will influence some behavior of the tab. So its state should be stored in Tab1
component, not in Tab1Controls
component. But how could I connect them, i.e. pass current value of the checkbox
from Tab1
instance to Tab1Controls
instance, and pass an event back from Tab1Controls
instance to Tab1
instance?
This could obviously be solved with Vuex
but I would like to avoid it.
General recommendation is to move state up the hierarchy, but I don't think it is possible with router. And anyway, it will make things a mess, because checkbox
data should belong to either Tab1
or Tab1Controls
, and has nothing to do with other tabs.
<router-view>
is a wrapper that loads components within. It does not bind any event listeners to those components – Phildata.attrs
would do this? github.com/vuejs/vue-router/blob/… – Estradiaz