实现点击空白处隐藏某节点

<span ref="projectButton">
	<el-popover v-model="visible" trigger="manual" placement="bottom" @show="show" @hide="hide">
	  <p>啦啦啦</p>
	  <el-button slot="reference" type="primary" @click="visible = !visible">show</el-button>
	</el-popover>
</span>


data () {
 return {
    visible: false
  }
},
methods: {
  show () {
    document.addEventListener('click', this.hidePanel, false)
  },
  hide () {
    document.removeEventListener('click', this.hidePanel, false)
  },
  hidePanel (e) {
    if (!this.$refs.projectButton.contains(e.target)) {
      this.visible = false
      this.hide()
    }
  }
}

  

posted @ 2020-06-04 11:06  不服憋着  阅读(287)  评论(0编辑  收藏  举报