.cursorrules (deprecated)
rules/vue3-composition/.cursorrules.cursorrules
Quality
81/100
Scores the file, not the repository.Length
927 words
18 headings · 5 code blocksRepository
16
— · pushed 109 days agoLast changed
2 days ago
First indexed 2 days ago.1# Vue 3 Composition API — Cursor Rules2# Comprehensive rules for Vue 3 development with the Composition API34## Project Context5You are working on a Vue 3 application using the Composition API with `<script setup>`6syntax. The project uses TypeScript, Vite as the build tool, and follows Vue's official7style guide recommendations. Pinia is used for state management and Vue Router for routing.89## Tech Stack10- Vue 3.4+ with `<script setup>` syntax11- TypeScript (strict mode)12- Vite for building and dev server13- Pinia for state management14- Vue Router 4+ for routing15- VueUse for composable utilities16- Vitest + Vue Test Utils for testing1718## Coding Style1920### Naming Conventions21- Components: PascalCase files matching component name (e.g., `UserProfile.vue`)22- Composables: camelCase with `use` prefix (e.g., `useAuth.ts`, `useFetchData.ts`)23- Stores (Pinia): camelCase with `use` prefix and `Store` suffix (e.g., `useUserStore.ts`)24- Event emits: kebab-case (e.g., `update:modelValue`, `item-selected`)25- Props: camelCase in script, kebab-case in template26- Directives: kebab-case with `v-` prefix in template27- Provide/Inject keys: Symbol constants in a shared file2829### File Structure30```31src/32 components/33 ui/ # Generic reusable UI components34 forms/ # Form-related components35 layout/ # Layout components (Header, Sidebar, Footer)36 composables/ # Shared composable functions37 stores/ # Pinia stores38 views/ # Route page components39 router/ # Router config and guards40 types/ # TypeScript type definitions41 utils/ # Pure utility functions42 assets/ # Static assets (images, fonts)43```4445## Component Patterns4647### Single File Component Order48```vue49<script setup lang="ts">50// 1. Type imports51// 2. Component imports52// 3. Composable usage53// 4. Props and emits definitions54// 5. Reactive state (ref, reactive, computed)55// 6. Watchers56// 7. Lifecycle hooks57// 8. Methods58</script>5960<template>61 <!-- Template content -->62</template>6364<style scoped>65/* Scoped styles */66</style>67```6869### Props and Emits with TypeScript70```vue71<script setup lang="ts">72interface Props {73 title: string;74 count?: number;75 items: Item[];76 variant?: 'primary' | 'secondary';77}7879const props = withDefaults(defineProps<Props>(), {80 count: 0,81 variant: 'primary',82});8384const emit = defineEmits<{85 'update:count': [value: number];86 'item-click': [item: Item, index: number];87}>();88</script>89```9091### Prefer92- `<script setup>` over `setup()` function93- `ref()` for primitives, `reactive()` for objects when destructuring is not needed94- `computed()` for derived state95- Composables to share logic between components96- `defineModel()` for two-way binding (Vue 3.4+)97- Template refs with `useTemplateRef()` (Vue 3.5+) or `ref<HTMLElement | null>(null)`98- `v-bind` shorthand and `v-on` shorthand99- Scoped styles to avoid leaking100101### Avoid102- Options API in new code (use Composition API exclusively)103- Mixins — use composables instead104- `this` keyword (not available in `<script setup>`)105- Mutating props directly — emit events to parent106- `reactive()` for primitives (loses reactivity on reassignment)107- Deeply nested `v-if`/`v-else` chains — use computed or component lookup108- Global event bus — use Pinia stores or provide/inject109- Watchers when `computed` would suffice110111## Composable Patterns112```ts113// composables/useFetch.ts114import { ref, watchEffect, type Ref } from 'vue';115116export function useFetch<T>(url: Ref<string> | string) {117 const data = ref<T | null>(null);118 const error = ref<Error | null>(null);119 const isLoading = ref(false);120121 async function execute() {122 isLoading.value = true;123 error.value = null;124 try {125 const response = await fetch(toValue(url));126 if (!response.ok) throw new Error(`HTTP ${response.status}`);127 data.value = await response.json();128 } catch (e) {129 error.value = e instanceof Error ? e : new Error(String(e));130 } finally {131 isLoading.value = false;132 }133 }134135 watchEffect(() => { execute(); });136137 return { data, error, isLoading, refetch: execute };138}139```140141## Pinia Store Patterns142```ts143// stores/useUserStore.ts144import { defineStore } from 'pinia';145import { ref, computed } from 'vue';146147export const useUserStore = defineStore('user', () => {148 const user = ref<User | null>(null);149 const isAuthenticated = computed(() => user.value !== null);150151 async function login(credentials: LoginCredentials) {152 user.value = await authApi.login(credentials);153 }154155 function logout() {156 user.value = null;157 }158159 return { user, isAuthenticated, login, logout };160});161```162163## Error Handling164- Use `onErrorCaptured()` lifecycle hook for component-level error boundaries165- Handle async errors in composables and expose error state via refs166- Use Vue Router `onBeforeRouteLeave` to prevent unsaved data loss167- Provide user-friendly error messages in the UI168- Type error states explicitly169170## Testing171- Use Vitest with `@vue/test-utils` for component testing172- Mount components with `mount()` for full rendering, `shallowMount()` for isolation173- Test composables independently by wrapping in a test component174- Mock Pinia stores with `createTestingPinia()`175- Test async behavior with `await flushPromises()`176- Prefer testing user-visible behavior over internal state177178## Performance Guidelines179- Use `v-once` for static content that never changes180- Use `v-memo` for expensive list rendering that rarely updates181- Use `defineAsyncComponent()` for lazy-loaded components182- Use `<KeepAlive>` for caching expensive component trees183- Use `shallowRef()` for large objects where deep reactivity is unnecessary184- Avoid expensive operations in computed — they re-run on every dependency change185- Use virtual scrolling for large lists (`vue-virtual-scroller`)186187## Common Pitfalls188- Destructuring `reactive()` objects loses reactivity — use `toRefs()` or keep as object189- Forgetting `.value` when accessing `ref()` in script (not needed in template)190- Watching a getter instead of a ref: `watch(() => state.count, ...)` vs `watch(countRef, ...)`191- Not using `toValue()` / `unref()` in composables to accept both refs and plain values192- Creating watchers without cleanup in composables used outside components193- Using `v-if` and `v-for` on the same element (v-if has higher priority in Vue 3)194- Forgetting `key` attribute on `<component :is>` to force re-mount on type change195- Not marking raw large objects with `markRaw()` when reactivity is unnecessary196
Also in survivorforge/cursor-rules
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| survivorforge/cursor-rulesrules/ai-ml-python/.cursorrules · 16 | .cursorrules | teststylearchdeployment+2 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/api-design-rest/.cursorrules · 16 | .cursorrules | lint-formatstylesecurityapi+3 | 69/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 92/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/aws-serverless/.cursorrules · 16 | .cursorrules | teststylearchtypes+6 | 73/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/chrome-extension/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+4 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/clean-code/.cursorrules · 16 | .cursorrules | styledo-notagent-behaviourdocs | 57/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/database-sql/.cursorrules · 16 | .cursorrules | styletypessecuritydatabase+3 | 65/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/devops-docker/.cursorrules · 16 | .cursorrules | setupbuildteststyle+4 | 93/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 16 | .cursorrules | buildteststylesecurity+3 | 93/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/django-rest/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/docker-devops/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 85/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/flutter-dart/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 89/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/fullstack-nextjs-prisma/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 96/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/go-gin/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+5 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/go-production/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+3 | 89/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/golang-api/.cursorrules · 16 | .cursorrules | buildteststylearch+6 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/langchain-ai/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+4 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mcp-server/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+7 | 68/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mern-stack/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mobile-react-native/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 89/100 | 2 days ago |
Diff against rules/ai-ml-python/.cursorrules Diff against rules/api-design-rest/.cursorrules Diff against rules/api-microservices/.cursorrules Diff against rules/aws-serverless/.cursorrules Diff against rules/chrome-extension/.cursorrules Diff against rules/clean-code/.cursorrules Diff against rules/database-sql/.cursorrules Diff against rules/devops-docker/.cursorrules Diff against rules/devops-infrastructure/.cursorrules Diff against rules/django-rest/.cursorrules Diff against rules/docker-devops/.cursorrules Diff against rules/flutter-dart/.cursorrules Diff against rules/fullstack-nextjs-prisma/.cursorrules Diff against rules/go-gin/.cursorrules Diff against rules/go-production/.cursorrules Diff against rules/golang-api/.cursorrules Diff against rules/langchain-ai/.cursorrules Diff against rules/mcp-server/.cursorrules Diff against rules/mern-stack/.cursorrules Diff against rules/mobile-react-native/.cursorrules
