Skip to content

createSharedComposable

Category
Export Size
213 B
Last Changed
15 minutes ago
Related

创建一个可在多个 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

Source

SourceDocs

贡献者

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)

Released under the MIT License.