实例:vue中点击空白区域关闭某个div图层
<template>
<div class="search" ref="searchMain">
<el-input v-model="value" placeholder="请输入搜索内容" ref="input"
@focus="getFocus"
@input="changeVal"
@clear='clearCard'
@blur="onBlurFocus"
clearable style="width:300px">
</el-input>
<el-button type="primary" icon="el-icon-search" @click="onSearch"></el-button> <!-- 点击空白区域关闭某个div图层 -->
<el-card>
<el-button @click="togglePanel">点击</el-button>
<div v-show="visible" ref="main">弹出层</div>
</el-card>
</div>
</template>
data() {
return {
visible: false
}
}
methods:{
// 点击空白区域关闭某个div图层
togglePanel () {
this.visible ? this.hide() : this.show()
},
show () {
this.visible = true
document.addEventListener('click', this.hidePanel, false)
},
hide () {
this.visible = false
document.removeEventListener('click', this.hidePanel, false)
},
hidePanel (e) {
if (!this.$refs.searchMain.contains(e.target)) {
this.hide()
}
}
实例:vue中点击空白区域关闭某个div图层的更多相关文章
- elementUI vue tree input 懒加载 输入下拉树型示例 点击其他区域关闭自定义div
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- js中点击空白区域时文本框与隐藏层的问题
当文本框获得焦点的时候,在文本框的下方显示一个浮动层. 当用户点击除了文本框和浮动层以外的网页空白处时,要隐藏浮动层. 当用户点击浮动层时,改变文本框的值. <!DOCTYPE html PUB ...
- 【转】Android点击空白区域,隐藏输入法软键盘
原文网址:http://www.2cto.com/kf/201505/401382.html 很多时候,我们在使用应用时,会出现输入法软键盘弹出的问题,通常情况下,我们默认会使用户点击返回键或者下一步 ...
- vue中点击屏幕其他区域关闭自定义div弹出框
直接上代码: mounted: function () { let that = this; $(document).on('click', function (e) { let dom = $('. ...
- Android popupwindow 失去焦点或者点击空白区域时消失的解决方法
先来看下Android API 的这个Methods: public void setOutsideTouchable (boolean touchable) Controls whether the ...
- vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单
需求是通过点击body页面,在其他地方就关闭这个<div>菜单,给这个div一个id:problemList,但是点击我打开的按钮,不关闭. created () { document.o ...
- vue中点击空白处隐藏弹框(用指令优雅地实现)
在写vue的项目的时候,弹框经常性出现,并要求点击弹框外面,关闭弹框,那么如何实现呢?且听我一一...不了,能实现效果就好 <template> <div> <div c ...
- vue中点击复制粘贴功能
1.下载clipboard.js cnpm install clipboard --save 2.引入,可以在mian.js中全局引入也可以在单个vue中引入 import Clipboard fro ...
- vue中点击添加class,双击去掉class
VUE中 html 中 <ul id="shoppingList" v-on:click="addClass($event)" class="i ...
随机推荐
- Problem 6: Sum square difference
The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...
- win 10 安装 maven安装包
学习jenkins 的时候,需要用到maven,第一次搞maven,记录下 一.准备工作,下载 jdk7.0以上版本 win10操作系统 maven安装包 下载地址 如下图 二.解压安装包 我的安 ...
- 绘客708s的设置
平时也有画画的想法,虽然画的不好,但是装备还是少不了的.因此,在大概一年之前就入手了绘客的708s的绘画板,10寸乘6寸的,很大,手绘方便多了. 在这段时间内,使用绘画板的时候还是遇到了一些问题,最主 ...
- 2017年5月12日15:10:46 rabbitmq不支持非阻塞调用服务器
就像昨天碰到的问题描述一样,问题不是出在消费者上而是在生产者发送消息出现没有得到返回值时消息通道被挂起,rabbitmq发送的消息是阻塞调用即当发生阻塞时,继续发送的消息都堆在后面.在网上看到有两个方 ...
- 运维shell全部语法进阶
Linux运维之shell脚本进阶篇 一.if语句的使用 1)语法规则 1 2 3 4 5 6 7 8 9 if [条件] then 指令 fi 或 if [条件];then ...
- c++ — 运算符重载与strcmp自实现
#include <iostream> #include <string.h> #include <stdlib.h> using namespace std; c ...
- Idea常用功能汇总
1.格式化代码:Ctrl+Alt+L 2.重命名变量:光标停留在变量上,Shift+F6 3.打开文件或者项目所在目录: 右键>Show in Explorer 4.添加包围代码块的快捷键:Ct ...
- win10操作系统 安装nodejs报2503错误解决方法
报该错误的原因是由于安装操作没有获得足够的管理权限导致. 在电脑左下角开始菜单[右键]选择"命令提示符(管理员)“ 敲入如下命令 msiexec /package 后面加你nodejs的本机 ...
- LSC问题(不连续问题)
转载:http://blog.csdn.net/v_JULY_v/article/details/6110269 本文是动态规划算法中,网上写得最好的一个之一.看完很容易理解.需要重点理解的部分,我会 ...
- mac pkg移除
1打开终端 sudo bash < <(curl -sL https://raw.github.com/mpapis/pkg_uninstaller/master/pkg-install) ...