virtual-trigger.vue 731 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <el-tooltip
  3. v-model:visible="visible"
  4. content="Bottom center"
  5. placement="bottom"
  6. effect="light"
  7. trigger="click"
  8. virtual-triggering
  9. :virtual-ref="triggerRef"
  10. />
  11. <el-button @click="visible = !visible">test</el-button>
  12. </template>
  13. <script setup lang="ts">
  14. import { onMounted, ref } from 'vue'
  15. const visible = ref(false)
  16. const triggerRef = ref({
  17. getBoundingClientRect() {
  18. return position.value
  19. },
  20. })
  21. const position = ref({
  22. top: 0,
  23. left: 0,
  24. bottom: 0,
  25. right: 0,
  26. })
  27. onMounted(() => {
  28. document.addEventListener('mousemove', (e) => {
  29. position.value = DOMRect.fromRect({
  30. width: 0,
  31. height: 0,
  32. x: e.clientX,
  33. y: e.clientY,
  34. })
  35. })
  36. })
  37. </script>