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>
$emit
, with or without an event bus to notify that the parent element should insert the sub-menu. – Heri Hehe Setiawanmenu: [ 'Item': { href: '#' } ]
is not a valid syntax you should domenu: [{ href: '#' } ]
– Boussadjra Brahim