我有一个Vue组件,它表示如下(ParentComponent.vue)所示的页面:
<template>
<div id="main-wrapper" class="appTravelytics">
<top-bar v-if="$route.path !== '/login'"></top-bar>
<div class="page-wrapper" v-if="$route.path !== '/login'">
<div class="container-fluid">
<breadcrumb ></breadcrumb>
<template>
<router-view :loggedIn="loggedIn"></router-view>
</template>
</div>
<footer-bar></footer-bar>
</div>
<template v-else>
<router-view :loggedIn="loggedIn"></router-view>
</template>
</div>
</template>BreadCrumb.vue:
<template>
<h3 class="text-themecolor m-b-0 m-t-0">{{ title }}</h3>
</template>
<script>
export default {
data () {
return {
title: 'Welcome'
}
},
created: function () {
this.$root.$on('page_title', function (data) {
console.log(data)
this.title = data
this.$nextTick()
})
}
}
</script>Content.vue (脚本部分):
export default {
created: function () {
this.$root.$emit('page_title', 'Page Title')
}
}由路由器定义的组件(在本例中标记为Content.vue)将放置在ParentComponent的路由器视图中,该组件需要与“面包屑”组件通信,以更新页面和面包屑的标题。
我试过一辆全球赛事巴士,我试过道具传球。在接收到发射信号时,您会注意到console.log。它很好地更新,使用VueJS调试器在chrome中,变量被填充。但我无法让它更新DOM/演示文稿。我搜索了所有的地方,得到了道具传递和全球巴士的推荐,但是缺少一些东西。
(请帮助:)
提前感谢!
发布于 2018-04-06 12:12:48
Vuex将更好地用于状态管理,这样您就可以从所有组件访问和更新必要的状态。
https://stackoverflow.com/questions/49685038
复制相似问题