Skip to content

createSharedComposable

类别
导出大小
261 B
最近修改
2 days ago
相关

使可组合函数可用于多个 Vue 实例。

🌐 Make a composable function usable with multiple Vue instances.

WARNING

当在 SSR 环境中使用时,createSharedComposable自动回退 到非共享版本。 这意味着每次调用都会在 SSR 中创建一个新的实例,以避免 跨请求状态污染

用法

🌐 Usage

ts
import { 
createSharedComposable
,
useMouse
} from '@vueuse/core'
const
useSharedMouse
=
createSharedComposable
(
useMouse
)
// CompA.vue const {
x
,
y
} =
useSharedMouse
()
// CompB.vue - will reuse the previous state and no new event listeners will be registered const {
x
,
y
} =
useSharedMouse
()