Vue Cursor Rules: Composition API and SFC Best Practices

Vue cursor rules for Composition API, single-file components, template syntax, reactivity, testing, and performance to produce clean, maintainable applications

November 14, 2025by PromptGenius Team
vuecursor-rulesfrontendcomposition-apisfc

Overview

Professional cursor rules for Vue that emphasize Composition API, single-file components, and template syntax. These rules help AI generate clean, accessible, and maintainable Vue code with complete context.

Note:

Optimizes Vue 3+ patterns with Composition API, reactive state, and SFC structure aligned to modern best practices.

Rules Configuration

.cursor/rules/vue.mdc

---
description: Enforces best practices for Vue development, focusing on context-aware code generation, component architecture, template syntax, and reactivity patterns. Provides comprehensive guidelines for writing clean, efficient, and maintainable Vue code with proper context.
globs: **/*.{vue,js,ts}
---
# Vue Best Practices

You are an expert in Vue 3+ development and related web technologies.
You understand modern Vue practices, architectural patterns, and the importance of complete context in code generation.

## Vue-Specific Rules

Cursor rules in Vue provide intelligent navigation and manipulation capabilities designed for Vue development. These rules help you work efficiently with components, directives, and template syntax.

### Component Navigation

- Navigate between component definitions and usages
- Jump to lifecycle hook declarations and methods
- Move between template sections and script blocks
- Access component props and computed properties

### Smart Selection

- Select template blocks and expressions
- Expand selection to include directives and arguments
- Smart component prop and event selection
- Select complete component definitions including all blocks

### Code Manipulation

- Quick component creation and refactoring
- Directive handling and optimization
- Computed property and watcher management
- Template structure manipulation

## Best Practices

- Use template-aware navigation for clear organization
- Leverage directive-specific cursor movements
- Utilize component-aware selection patterns
- Follow Vue component lifecycle patterns
- Implement Composition API patterns where applicable

Key Features

🧩

SFC Structure Awareness

Template, script, and style block navigation with context

⚙️

Composition API

ref vs reactive, computed, and watch patterns with clarity

🧪

Testing Built-In

Generate tests with Vue Test Utils and Vitest/Jest

📘

Type Safety

Prop validation and TS integration for robust components

Accessibility

ARIA roles, keyboard navigation, and semantic markup

Performance

Lazy loading, code splitting, and reactive optimization

Installation

1

Choose Your IDE

Select the appropriate file path based on your development environment.

2

Create the Rules File

Create the cursor rules file in your project using the tabs above.

3

Add the Rules Configuration

Copy the configuration markdown into the file.

4

Start Building

Your AI assistant will follow Vue best practices automatically.

Examples

<template>
  <div class="user-profile">
    <h1>{{ user.name }}</h1>
    <UserStats :stats="userStats" @update="handleUpdate" />
  </div>
</template>

<script>
export default {
  name: 'UserProfile',
  props: {
    user: { type: Object, required: true }
  },
  data() {
    return { userStats: null }
  },
  computed: {
    fullName() { return `${this.user.firstName} ${this.user.lastName}` }
  },
  methods: {
    handleUpdate(stats) { this.userStats = stats }
  }
}
</script>

<script setup>
import { ref, computed, onMounted } from 'vue'

const props = defineProps({ userId: { type: String, required: true } })

const user = ref(null)
const userStats = ref(null)

const fullName = computed(() => {
  if (!user.value) return ''
  return `${user.value.firstName} ${user.value.lastName}`
})

onMounted(async () => {
  user.value = await fetchUser(props.userId)
})

function handleUpdate(stats) {
  userStats.value = stats
}
</script>

Configuration

Customize Vue-specific cursor rules in your settings:

{
  "vue.cursorRules": {
    "componentNavigation": true,
    "smartSelection": true,
    "templateHandling": true,
    "compositionApiSupport": true,
    "directiveAwareness": true
  }
}

Use Cases

Component Libraries

Reusable UI components with clear props and stories

Vue Applications

Feature-rich apps with state management and routing

Nuxt Full-Stack

Server-first apps with hybrid rendering strategies

Design Systems

Consistent UI with tokens, themes, and accessibility

Note:

These rules work with any Vue project and pair well with Nuxt. Adjust framework-specific sections as needed.