VueUse createSharedComposable 组件间共享事件,可以解决重复监听事件的问题。
A组件用法
import { computed, onMounted, reactive } from 'vue';
import { createSharedComposable, useMouse } from '@vueuse/core'
const useSharedMouse = createSharedComposable(useMouse)
// CompA.vue
const point = useSharedMouse()
B组件用法
import { computed, onMounted, reactive } from 'vue';
import { createSharedComposable, useMouse } from '@vueuse/core'
const useSharedMouse = createSharedComposable(useMouse)
// CompB.vue
const point = useSharedMouse()
例子