ClickOutSide.vue 396 字节
Newer Older
陈文彬 已提交
1
<template>
V
vben 已提交
2 3 4
  <div ref="wrap">
    <slot></slot>
  </div>
陈文彬 已提交
5
</template>
V
vben 已提交
6 7
<script lang="ts" setup>
  import { ref, onMounted } from 'vue';
V
Vben 已提交
8
  import { onClickOutside } from '@vueuse/core';
9

V
vben 已提交
10 11
  const emit = defineEmits(['mounted', 'clickOutside']);
  const wrap = ref<ElRef>(null);
12

V
vben 已提交
13 14 15
  onClickOutside(wrap, () => {
    emit('clickOutside');
  });
V
vben 已提交
16

V
vben 已提交
17 18
  onMounted(() => {
    emit('mounted');
陈文彬 已提交
19 20
  });
</script>