跳到内容

createSharedComposable

类别
导出大小
232 B
最后更改
4 months ago
相关

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

用法

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

类型声明

typescript
/**
 * Make a composable function usable with multiple Vue instances.
 *
 * @see https://vueuse.vuejs.ac.cn/createSharedComposable
 */
export declare function createSharedComposable<Fn extends AnyFn>(
  composable: Fn,
): Fn

源码

SourceDocs

贡献者

Anthony Fu
Anthony Fu
XinXiao
童欧巴
Egor Kotlyarov

更新日志

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: 移除 Vue 2 支持,优化捆绑包并清理 (#4349)
v11.0.2 on 8/24/2024
a2441 - fix: 处理可组合函数的返回值为空的情况 (#4151)

在 MIT 许可证下发布。