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

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

created () {
  document.onclick = function () {
  // 要关闭的div的id (problemList) document.getElementById('problemList').style.display = 'none' } },

点击按钮打开模态框的方法要写个阻止冒泡事件,不然会点不开

getItme() 是点击打开div的事件

// 控制问题列表的显示和关闭
getItme (e, num) {
  this.stopEvent(e)
  document.getElementById('problemList').style.display = 'block'
},

  

原文地址:https://www.cnblogs.com/wgl0126/p/10727955.html