Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Selects and applies VueUse composables for Vue.js and Nuxt projects.
83% 96%+13 ptsof test cases passed
Passed 22 of 23 test cases with the skill, and 19 of 23 without it.
3 of 3 safety checks passed
35 agent runs
2 forksA fork is a copy of this skill that someone made so they could edit it for their own use. The original doesn't change.
Create global state that can be injected into components.
// useCounterStore.ts
import { createInjectionState } from '@vueuse/core'
import { computed, shallowRef } from 'vue'
const [useProvideCounterStore, useCounterStore] = createInjectionState((initialValue: number) => {
// state
const count = shallowRef(initialValue)
// getters
const double = computed(() => count.value * 2)
// actions
function increment() {
count.value++
}
return { count, double, increment }
})
export { useProvideCounterStore }
// If you want to hide `useCounterStore` and wrap it in default value logic or throw error logic, please don't export `useCounterStore`
export { useCounterStore }
export function useCounterStoreWithDefaultValue() {
return useCounterStore() ?? {
count: shallowRef(0),
double: shallowRef(0),
increment: () => {},
Next to this one in the catalogue, plus more from the same author.