vue中点击其他任意位置关闭弹框


    mounted() {
        //点击任意位置关闭区域弹窗
        document.addEventListener('click', (e) => {

            //获取弹窗对象
            const userCon = document.getElementsByClassName('tanKuang')[0];
            const userCon1 = document.getElementsByClassName('tanKuang')[1];

            //判断弹窗对象中是否包含点击对象
            if (userCon && !userCon.contains(e.target)&& !userCon1.contains(e.target)) {
                //如果包含则跳转回之前的页面
                this.isShowModal = false;
            }

        })

    },

 

posted @ 2022-06-29 18:21  李云蹊  阅读(836)  评论(0编辑  收藏  举报