需求是通過點擊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' },