<div class="but-alert" @click="lookDetail()">查看详情</div>
<div class="weather-forecast">详情页面</div>
function bodyClick(e: any) {
const but = document.querySelector('.but-alert')
const dialog = document.querySelector('.weather-forecast')
// 重点是contains,是否包含元素
if (but && !but.contains(e.target) && dialog && !dialog.contains(e.target) ) {
weatherDialog.value = false;
}
}
// 页面点击他处,控制弹窗显示隐藏
document.addEventListener('click', (e) => {
bodyClick(e)
});