I am currently learning Vue.js for a project I am busy with. I have been learning through online resources, as well as a Udemy course by Maximilian Schwarzmüller, Which i'd highly recommend.
I am having an issue building a hamburger menu for practice purposes. I am adding/removing a class on a div which holds my menu content. The adding/removing of the class happens via a button click (my "hamburger").
As far as I can tell through my course and other online sources, including a good few StackOverflow questions, what I have done should work.
Please let me know if you can see any issues, as it isn't working in my codepen. Thanks in advance =)
relevant HTML:
<button v-on:click="isActive = !isActive" class="navigation-hamburger">
<p>-<br>-<br>-</p>
</button>
<div class="menu-contain" v-bind:class="{ active: isActive}">
<ul>
<li><a href="#" class="links">Home</a></li>
<li><a href="#" class="links">About</a></li>
<li><a href="#" class="links">Contact</a></li>
</ul>
</div>
CSS:
.menu-contain {
width: 100%;
height: 0px;
background-color: #09333C;
transition: all 0.5s linear;
}
.active {
width: 100%;
height: 300px;
background-color: #8BAFB5;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.5s linear;
}
Vue js:
new Vue({
el: '#wrap',
data: {
isActive: false
}
});
Here is the codepen:
</div>tag that is closing the#wrapdiv too early meaning your.menu-containdiv is outside the scope of your Vue instance. Here's a working codepen: codepen.io/anon/pen/PKJKRM