Skip to content

createSharedComposable

Category
Export Size
232 B
Last Changed
4 months 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()

Type Declarations

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

Source

SourceDocs

Contributors

Anthony Fu
丶远方
Anthony Fu
XinXiao
童欧巴
Egor Kotlyarov

Changelog

0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
a2441 - fix: handle the case where the return value of composable function is empty (#4151)

Released under the MIT License.