<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图层的更多相关文章

  1. elementUI vue tree input 懒加载 输入下拉树型示例 点击其他区域关闭自定义div

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  2. js中点击空白区域时文本框与隐藏层的问题

    当文本框获得焦点的时候,在文本框的下方显示一个浮动层. 当用户点击除了文本框和浮动层以外的网页空白处时,要隐藏浮动层. 当用户点击浮动层时,改变文本框的值. <!DOCTYPE html PUB ...

  3. 【转】Android点击空白区域,隐藏输入法软键盘

    原文网址:http://www.2cto.com/kf/201505/401382.html 很多时候,我们在使用应用时,会出现输入法软键盘弹出的问题,通常情况下,我们默认会使用户点击返回键或者下一步 ...

  4. vue中点击屏幕其他区域关闭自定义div弹出框

    直接上代码: mounted: function () { let that = this; $(document).on('click', function (e) { let dom = $('. ...

  5. Android popupwindow 失去焦点或者点击空白区域时消失的解决方法

    先来看下Android API 的这个Methods: public void setOutsideTouchable (boolean touchable) Controls whether the ...

  6. vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单

    需求是通过点击body页面,在其他地方就关闭这个<div>菜单,给这个div一个id:problemList,但是点击我打开的按钮,不关闭. created () { document.o ...

  7. vue中点击空白处隐藏弹框(用指令优雅地实现)

    在写vue的项目的时候,弹框经常性出现,并要求点击弹框外面,关闭弹框,那么如何实现呢?且听我一一...不了,能实现效果就好 <template> <div> <div c ...

  8. vue中点击复制粘贴功能

    1.下载clipboard.js cnpm install clipboard --save 2.引入,可以在mian.js中全局引入也可以在单个vue中引入 import Clipboard fro ...

  9. vue中点击添加class,双击去掉class

    VUE中 html 中 <ul id="shoppingList" v-on:click="addClass($event)" class="i ...

随机推荐

  1. CISCO 关闭4786端口解决方法

    先确认交换机是否支持smart install服务 检查命令如下: switch#show vstack config | inc Role Role:Client (SmartInstall ena ...

  2. centos7 下 安装部署nginx

    centos7 下 安装部署nginx 1.nginx安装依赖于三个包,注意安装顺序 a.SSL功能需要openssl库,直接通过yum安装: #yum install openssl b.gzip模 ...

  3. Python入门学习例子——从Hao123获取图片

    import urllib.requestimport re #获取html页面内容def getHtml(url): data=urllib.request.urlopen(url) pageCon ...

  4. git clone 带用户名密码

    git使用用户名密码clone的方式: git clone http://username:password@remote eg: username:  abc@qq.com, pwd: test, ...

  5. json元素顶部插入unshift、尾部插入push、顶部获取shift、尾部获取pop

    1)json元素插入 var json=[ //顶部位置 {id:1,name:'B'}, {id:2,name:'C'}, {id:3,name:'D'}, //尾部位置 ] 顶部位置)json.u ...

  6. NGINX 502错误排查(转)

    一.NGINX 502错误排查 NGINX 502 Bad Gateway错误是FastCGI有问题,造成NGINX 502错误的可能性比较多.将网上找到的一些和502 Bad Gateway错误有关 ...

  7. spring Onions and wine

    Before and after the cold dew, the air is drier and the "autumn dryness" is vulnerable. Nu ...

  8. vue的$nextTick使用总结,this.$refs为undefined的解决办法,element Ui的树形控件setCheckedKeys方法无法使用

    其实这3个讲的是一个问题,先说下问题,我在watch里设置一个监听,当弹窗打开时,自动添加树形的默认选中项, 但奇怪的是this.$refs为undefined,自然setCheckedKeys无法使 ...

  9. 第一周CTF (合天CTF)

    0X00 第一周 0x01 基础 50 . 下载下来发现是一个exe文件 ,尝试了一下没打开,然后把后缀名一个一个的试一试,改成txt用记事本打开,得到了一个“假冒的flag” *(别问我怎么知道的) ...

  10. python基础14_文件操作

    文件操作,通常是打开,读,写,追加等.主要涉及 编码 的问题. #!/usr/bin/env python # coding:utf-8 ## open实际上是从OS请求,得到文件句柄 f = ope ...