name: Banana
color: Yellow
size: Medium

createGlobalState

Keep states in the global scope to be reusable across Vue instances.

Usage

// store.js
import { createGlobalState, useStorage } from '@vueuse/core'

export const useGlobalState = createGlobalState(
  () => useStorage('vue-use-local-storage'),
)
// component.js
import { useGlobalState } from './store'

export default defineComponent({
  setup() {
    const state = useGlobalState()
    return { state }
  },
})

Type Declarations

/**
 * Keep states in the global scope to be reusable across Vue instances.
 *
 * @link /createGlobalState
 * @param stateFactory A factory function to create the state
 */
export declare function createGlobalState<T extends object>(
  stateFactory: () => T
): () => T

Source

SourceDemoDocs