Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

how to set up vuex with typescript

// store.ts
import { InjectionKey } from 'vue'
import { createStore, Store } from 'vuex'

// define your typings for the store state
export interface State {
  count: number
}

// define injection key
export const key: InjectionKey<Store<State>> = Symbol()

export const store = createStore<State>({
  state: {
    count: 0
  }
})

// define your own `useStore` composition function
export function useStore () {
  return baseUseStore(key)
}

// main.ts
import { createApp } from 'vue'
import { store, key } from './store'

const app = createApp({ ... })

// pass the injection key
app.use(store, key)

app.mount('#app')
Comment

PREVIOUS NEXT
Code Example
Typescript :: nest js decorator 
Typescript :: multi select + search + Multiselect and Search in angular 13 
Typescript :: optional or required depending on param is true react typescript 
Typescript :: Write a prolog program to find the sum of elements in given list. 
Typescript :: Local Variable in Jenkins 
Typescript :: how to take list as command line arguments in python 
Typescript :: extracting digits from a number in c++ 
Typescript :: typescript isvalidguid 
Typescript :: create seperate file for requests react 
Typescript :: Lua programming - setting up physics 
Typescript :: The create-react-app imports restriction outside of src directory 
Typescript :: how to call a function in a macro with variadic arguments c++ 
Typescript :: reader.readasarraybuffer(file) is undefined 
Typescript :: number of elements in circular queue 
Typescript :: redux toolkit socket io 
Typescript :: economic tracking portfolio construction 
Typescript :: CUSTOM_ELEMENTS_SCHEMA error occur while unit testing with jasmine and karma 
Typescript :: which of the following object types below cannot be replicated 
Typescript :: TypeError: agent_go() takes 0 positional arguments but 1 was given 
Typescript :: circular indicator gets whole page flutter 
Typescript :: INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. 
Typescript :: typescript dynamic type 
Typescript :: where to put toaster on http service calls typescript 
Typescript :: windows 10 iso 
Cpp :: print set c++ 
Cpp :: platform io change baud rate 
Cpp :: how to print items in arduino 
Cpp :: c++ get length of array 
Cpp :: power function in O(log(n)) time c++ 
Cpp :: qt qlcdnumber change value 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =