Skip to content

createSharedComposable

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

¥Make a composable function usable with multiple Vue instances.

用法

¥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
()

类型声明

ts
export type 
SharedComposableReturn
<
T
extends
AnyFn
=
AnyFn
> =
T
/** * Make a composable function usable with multiple Vue instances. * * @see https://vueuse.org/createSharedComposable */ export declare function
createSharedComposable
<
Fn
extends
AnyFn
>(
composable
:
Fn
,
):
SharedComposableReturn
<
Fn
>

源代码

源代码文档

变更日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)