Home  >  Article  >  Web Front-end  >  The implementation method of closing the component after clicking on the component in Vue

The implementation method of closing the component after clicking on the component in Vue

php中世界最好的语言
php中世界最好的语言Original
2018-03-28 17:03:474272browse

This time I will bring you the implementation method of closing the component after clicking on the component in Vue. What are the precautions of how to close the component after clicking on the component in Vue. The following is a practical case, let’s take a look. one time.

Vue defines a global click function, and the parameter is the callback function of the click.

Vue.prototype.globalClick = function (callback) { //页面全局点击
 $(document).click(callback);
}

Listen to global click events after the component is mounted

mounted:function () {
 this.globalClick(this.handleClickOut);
},

Hide elements.

Get the dom node, determine whether the parent exists to determine whether it needs to be closed

handleClickOut:function (event) {
 if($(event.target).parents(".sys-add-user-dialog").length == 0){
  //隐藏元素
 }
},

I believe you have mastered the method after reading the case in this article, please come for more exciting information Pay attention to other related articles on php Chinese website!

Recommended reading:

How vue.js inserts variable parameters in tag attributes

vue-cli when packaging code How to extract project-related configuration files

The above is the detailed content of The implementation method of closing the component after clicking on the component in Vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn