在Vue.js模板中使用事件总线或道具
我有一个主页,用适当的道具调用所有模板,比如在Vue.js模板中使用事件总线或道具,vue.js,components,vue-component,vuex,Vue.js,Components,Vue Component,Vuex,我有一个主页,用适当的道具调用所有模板,比如 <sideBar :menu="menu"></sideBar> <topBar></topbar> <mainContent><mainContent> 因为嵌套对象如下所示: menu:{topLevelA:{midLevelA1:'lowContentA1'}, {midLevelA2:'lowContentA2'}, topL
<sideBar :menu="menu"></sideBar>
<topBar></topbar>
<mainContent><mainContent>
因为嵌套对象如下所示:
menu:{topLevelA:{midLevelA1:'lowContentA1'},
{midLevelA2:'lowContentA2'},
topLevelB:{midLevelB1:'lowContentB1'}}
当然,如果使用道具,我可以很容易地传递给孩子和孙子,但缺点是,很难找到模板设计,它看起来杂乱无章,分散在几个地方,不像我现在看到的单个页面
我可以通过使用emit event甚至Vuex选择具有相同级别子级的主页,但这似乎不自然。。嗯
有没有更好的办法
为清晰起见,请编辑:
<template>
<div class="window">
<div class="window-content">
<div class="pane-group">
<sidebar-page-view :custList="custList"></sidebar-page-view>
<div class="pane">
<topbar-header-view :custMenu="custMenu"></topbar-header-view>
<window-pane-view :content="content"></window-pane-view>
<div class="toolbar toolbar-footer">
</div>
</div>
</div>
</div>
</div> <!-- Window Content Ends -->
它本质上是分层的,所以道具流更有意义,因为只有方法功能可以启动,而只有一个层次
I have now _sidebar (custList) it has to be initiated with eventBus or vuex
|
Main--|-topbar (custMenu)
|_
windowPane (content)
如果没有(最低限度但现实的)你想做什么,就不可能回答这个问题。对不起,没有说清楚,为了清楚起见,如上所述进行了编辑。我不会让一个组件打开标签,而不是关闭标签,如在“对”下。谢谢,@RoyJ,事实证明,我使用的是vuex,因为它不是组件内部的组件,毕竟是模板,这引发了另一个问题,但这是在另一个线程中。
<template>
<div class="window">
<div class="window-content">
<div class="pane-group">
<sidebar-page-view :custList="custList"></sidebar-page-view>
<div class="pane">
</template>
<template>
<topbar-header-view :custMenu="custMenu"></topbar-header-view>
<window-pane-view :content="content"></window-pane-view>
</template>
<template>
<window-pane-view :content="content"></window-pane-view>
<div class="toolbar toolbar-footer">
</div>
</div>
</div>
</div>
</div> <!-- Window Content Ends -->
</template>
CustomerList A-CustomerA Menu 1-Content 1
-Content 2
-CustomerA Menu 2
-CustomerA Menu 3 -Content 1
-Content 2
CustomerLust B-
...
I have now _sidebar (custList) it has to be initiated with eventBus or vuex
|
Main--|-topbar (custMenu)
|_
windowPane (content)