if-pinia
v1.0.9
Published
userful functions for pinia
Downloads
22
Readme
if-pinia
provide some useful functions to imporve the development experience
extendStore(name, module, persistedstates)
Extends Store instance (Pinia)
const name = 'example'
const module = {
state:() => {
return {
name: 'Example Store',
version: 'beta',
counter: {
num: 0
}
}
},
getters: {
count: state => state.counter.num
},
actions: {
plus(offset) {
this.counter.num += offset
}
}
}
// Default
extendStore(name, module)
// vuex-persistedstate
extendStore(name, module, ['counter.num''])
useStoreByModule(name)
useRef
and useRefs
return computed values (readonly)
const {store, useRef, useRefs, dispatch} = useStoreByModule('example')
useRef('counter.num') // 0
useRefs(['counter.num', 'name', 'version']) // [0, 'Example Store', 'beta']
dispatch('plus', 3) // 3
useRefs({num: 'counter.num'}) // {num: 3}
store.counter.num // 3