Skip to content

createSharedComposable

类别
导出体积
213 B
上次更改
3 minutes ago
相关

创建一个可在多个 Vue 实例中使用的可组合函数。

用法

ts
import { createSharedComposable, useMouse } from '@vueuse/core'

const useSharedMouse = createSharedComposable(useMouse)

// CompA.vue
const { x, y } = useSharedMouse()

// CompB.vue - 将重用先前的状态,不会注册新的事件监听器
const { x, y } = useSharedMouse()

类型声明

typescript
/**
 * 使可组合函数可用于多个 Vue 实例。
 *
 * @see https://vueuse.org/createSharedComposable
 */
export declare function createSharedComposable<Fn extends AnyFn>(
  composable: Fn,
): Fn

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
XinXiao
童欧巴
Egor Kotlyarov

更新日志

v11.0.2 on 8/24/2024
a2441 - fix: handle the case where the return value of composable function is empty (#4151)