Skip to content
On this page

createSharedComposable

Category
Last Changed
3 months ago

Make a composable function usable with multiple Vue instances.

Usage

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

Type Declarations

/**
 * Make a composable function usable with multiple Vue instances.
 *
 * @see https://vueuse.org/createSharedComposable
 */
export declare function createSharedComposable<
  Fn extends (...args: any[]) => any
>(composable: Fn): Fn
/**
 * Make a composable function usable with multiple Vue instances.
 *
 * @see https://vueuse.org/createSharedComposable
 */
export declare function createSharedComposable<
  Fn extends (...args: any[]) => any
>(composable: Fn): Fn

Source

SourceDocs

Contributors

Anthony Fu
Egor Kotlyarov

Changelog

v6.3.0 on 9/8/2021
9e006 - fix: use tryOnScopeDispose instead of onScopeDispose (#725)
v6.0.0-beta.1 on 7/16/2021
7cb1f - feat: new function
createSharedComposable has loaded