Home > Web Front-end > JS Tutorial > 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中世界最好的语言
Release: 2018-03-28 17:03:47
Original
4372 people have browsed it

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);
}
Copy after login

Listen to global click events after the component is mounted

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

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){
  //隐藏元素
 }
},
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template