In order for the Home component to be aware of any clicks outside of the Nav component, I implemented a specific process. This was made possible by having the nav element nested within the Home Component.
The template for my Home component looks like this:
<div>
<nav-bar ref="nav"></nav-bar>
<div @click="useHideNavMethod()">
By using ref="nav"
, I am able to access and utilize methods from the Nav component in the Home component. This setup allows me to invoke the hideNav() method (which is located in the Nav component).
I intentionally positioned the nav outside of the div with the click event, so that clicking anywhere other than the Nav would trigger the useHideNavMethod() function.
In the template of my Nav component, I have:
<nav id="nav">
This is what is referenced when I make use of ref="nav"
.
Within the hideNav() method, I have included
this.styleNavLi.display = 'none';
in order to hide the navigation bar.
To call this method from the Home component, all I need to do is:
useHideNavMethod() {
this.$refs.nav.hideNav();
}