vue-development
Vue.js Development Standards
Apply these standards when developing Vue.js 3 applications with the Composition API.
General Guidelines
- Use Vue 3 with the Composition API for all new components
- Organize code by feature/module; keep related files together
- Use single-file components (
.vue) with<script setup>,<template>, and<style scoped>sections in that order - Place sections in order:
<script setup>→<template>→<style scoped> - Prefer
<script setup>syntax for simplicity and type inference - Use TypeScript in Vue components when possible
Naming Conventions
- PascalCase for component names and file names (e.g.,
MyComponent.vue) - kebab-case for custom event names and props in templates
- Composables should follow the
useXyzpattern
Component Structure
Props and Emits
- Always define
propswith types and default values where appropriate - Use
defineEmitsanddefinePropsfor event and prop definitions
State Management
- Use
refandreactivefor state; avoid usingthis - Use composables (
useXyz) for reusable logic
Templates
- Use
v-bindandv-onshorthand (:and@) - Use
v-if/v-elsefor conditional rendering - Use
v-forfor lists; always provide a unique:key - Avoid logic in templates; keep templates declarative and move logic to the script section
Styling
- Use CSS modules or
<style scoped>for component styles - Avoid global styles
Code Quality
- End every statement with a semicolon
- Use single quotes for strings
- Avoid using
anytype; prefer explicit types - Write clear JSDoc/TSDoc comments for composables and complex logic
- Follow accessibility and UI guidelines for all components
- Write unit tests for all components using Vitest
Example Component
<script setup lang="ts">
import { ref, computed } from 'vue'
import { defineProps, defineEmits } from 'vue'
interface Props {
title: string
disabled?: boolean
}
const props = defineProps<Props>()
const emit = defineEmits<{
(e: 'click'): void
(e: 'update', value: string): void
}>()
const counter = ref(0)
const displayTitle = computed(() => `${props.title} (${counter.value})`)
const onClick = () => {
if (!props.disabled) {
counter.value++
emit('click')
}
}
</script>
<template>
<div class="card">
<h2>{{ displayTitle }}</h2>
<button @click="onClick" :disabled="disabled" class="btn">Click me</button>
</div>
</template>
<style scoped>
.card {
padding: 1rem;
border: 1px solid #ccc;
border-radius: 8px;
}
.btn {
padding: 0.5rem 1rem;
background-color: #42b983;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
</style>
Example Composable
// composables/useCounter.ts
import { ref, computed } from 'vue'
export const useCounter = (initialValue = 0) => {
const count = ref(initialValue)
const doubleCount = computed(() => count.value * 2)
const increment = () => {
count.value++
}
const decrement = () => {
count.value--
}
const reset = () => {
count.value = initialValue
}
return {
count,
doubleCount,
increment,
decrement,
reset
}
}
When to Apply
Apply these standards when:
- Creating new Vue components
- Writing composables
- Reviewing or refactoring Vue code
- User asks about Vue.js best practices
- Working with Vue 3 Composition API
More from devbyray/github-copilot-starter
html-standards
Guidelines for writing HTML that is accessible, semantic, maintainable, and secure. Use when working with .html, .vue, .twig, .php, .cshtml, .svelte files, or when the user asks about HTML structure, semantic markup, accessibility, or web security best practices.
10markdown-standards
Documentation and content creation standards for Markdown files. Use when creating or editing .md files, writing documentation, README files, or when the user asks about Markdown formatting, content structure, front matter, or documentation best practices.
6css-standards
Guidelines for writing CSS that is simple, readable, and maintainable. Use when working with .css, .scss, .sass files, CSS-in-JS, styled-components, or when the user asks about CSS organization, selectors, specificity, reusability, performance, or responsive design patterns.
4javascript-typescript-standards
Guidelines for writing JavaScript and TypeScript code that is simple, readable, and maintainable. Use when working with .js, .jsx, .ts, .tsx, .mjs, .cjs files, or when the user asks about JavaScript/TypeScript coding standards, ES2022 features, Node.js modules, async/await patterns, or testing with Vitest.
4nuxt-development
Standards for Nuxt.js 3 development with auto-imports, file-based routing, and SSR/SSG capabilities. Use when working with Nuxt projects, pages/, layouts/, composables/ directories, or when the user asks about Nuxt-specific patterns, server-side rendering, or Nuxt configuration.
3testing-tdd
Test-Driven Development workflow and testing standards. Use when writing tests, implementing TDD, working with Vitest (frontend), xUnit or MsTest (backend), or when the user asks about testing strategies, test coverage, or TDD methodology.
3