rules/vue/patterns.md
This file extends common/patterns.md with Vue specific content.
useXxx) is the reusable-logic unit. In Feature-Sliced Design it lives in the slice model segment.MaybeRefOrGetter<T> inputs and normalize with toValue, so callers can pass a ref, a getter, or a raw value.toRefs(reactive(...)) so consumers can destructure without losing reactivity.provide / inject must be called inside a component setup, not lazily or conditionally.defineProps<Props>() and tuple-form defineEmits<{ change: [id: number] }>().defineModel<T>('name', { default }) for two-way binding. It compiles to a prop plus an update:* emit.provide / inject for tree-scoped data without prop drilling.const key = Symbol() as InjectionKey<T>.readonly ref plus an explicit updater function, never a raw mutable ref.ref is state, computed is getters, function is actions.$reset for free. Define your own.storeToRefs for state and getters. Destructure actions directly off the store.localStorage.import().beforeEach auth gate keyed on meta.requiresAuth. Guards return false (cancel), a route location (redirect), or undefined / true (continue).() => route.params.id, not the whole route object.@tanstack/vue-query owns server-cache state. Pinia owns client state.queryOptions factories in the FSD api segment..value. Passing .value freezes the key and kills reactive refetch.useQuery({ queryKey: ['auction', id], queryFn: () => fetchAuction(toValue(id)) })
// after a mutation
queryClient.invalidateQueries({ queryKey: ['auction', id] })
frontend-patterns, vite-patterns.