[Vuejs]-Close menu when user clicks on div

0👍

I guess you want to open/close menu on click. So you can do this in Vue:

export default {
  data() {
    return {
      show: true
    }
  },
  methods: {
    toggle() {
      // my different actions...
      this.show = !this.show
    }
  }
}
<div v-if="show">
  My menu
</div>
<div @click="toggleMenu">
  Your button/container to show/hide menu
</div>

Here you attach your variable "show" to display or not the element you want. And you attach your "click" function to the element you want to click to show/hide your element.

Leave a comment