I have a Vue Bootstrap SPA with the following structure:
- layout
- navbar
- breadcrumb
- router view
- component
- some content
I would like my component
to inject a submenu to the parent's navbar. For example:
export default {
name: 'Component',
data() {
return {
menu: [
'Item': {
href: '#'
}
]
}
},
mounted() {
parent.menu.addItem(this.menu)
}
}
Is this possible to do something like this?
Here the top layout:
<template>
<div>
<navbar :menu="menu"></navbar>
<router-view></router-view>
</div>
</template>
<script>
import NavBar from './navbar'
export default {
components: {
navbar: NavBar
},
data() {
return {
menu: [
{
text: "Foo",
href: "/foo",
},
{
text: "Bar",
href: "#",
},
],
};
},
};
</script>
You could emit an event to the parent component like :
in parent :