vue3的弹窗组件,现在有一个问题就是,当我点击打开弹窗后,鼠标在弹窗内按下不松开,移到弹窗外再松开,怎么样让他不关闭,如果是单独点击弹窗外,正常关闭。
<script setup>
const show = ref(false)
const open = () => {
show.value = true;
window.addEventListener('click', close);
}
const close = () => {
show.value = false;
window.removeEventListener('click', close);
}
</script>
<template>
<button @click.stop.prevent="open()" type="button">打开</button>
<div v-if="show" @click.stop.prevent style="background: #000000; width: 300px; height: 300px;">
<h1>弹窗</h1>
<button @click.stop.prevent="close()" type="button">关闭</button>
</div>
</template>
<style scoped>
</style>