Skip to content

Instantly share code, notes, and snippets.

@zmts
Last active January 26, 2019 17:12
Show Gist options
  • Save zmts/e3b5ad4f964735f259687730f599eaf0 to your computer and use it in GitHub Desktop.
Save zmts/e3b5ad4f964735f259687730f599eaf0 to your computer and use it in GitHub Desktop.
Handle outside click (Vue.js)

Handle outside click(Vue.js)

Скритие DOM елемента при клике не по нему.

data () {
  return {
    isOpen: false
  }
},

methods: {
  handleClickOutside(evt) {
    if (!this.$el.contains(evt.target)) {
      this.isOpen = false;
    }
  }
},

mounted() {
  document.addEventListener('click', this.handleClickOutside)
},

destroyed() {
  document.removeEventListener('click', this.handleClickOutside)
}

https://alligator.io/vuejs/vue-a11y-autocomplete/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment