Index of every page on this site: llms.txt
All skills
ejirocodes avatar

/vue-best-practices

@6e805e4
Run it yourself

Vue 3 and Vue.js best practices for TypeScript, vue-tsc, Volar, and component patterns. Use when writing, reviewing, or refactoring Vue 3 components with TypeScript, configuring Volar/vueCompilerOptions, extracting component types, working with defineModel/withDefaults, setting up Pinia store tests, or debugging Vue tooling issues. Triggers on Vue components, props extraction, wrapper components, template type checking, strictTemplates, vueCompilerOptions, Volar 3, CSS modules, fallthrough attributes, defineModel, withDefaults, deep watch, vue-router typed params, Pinia mocking, HMR SSR, moduleResolution bundler, useTemplateRef, onWatcherCleanup, useId, generic components, reactive props destructure.

Use this Skill: https://skilld.dev/gh/ejirocodes/agent-skills/vue-best-practices

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesvolar.md

≈2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Volar Configuration

Table of Contents


Volar 3.0 Breaking Changes

Volar 3.0 (vue-language-server 3.x) introduced breaking changes to the language server protocol. Editors configured for Volar 2.x will break.

Symptoms

  • vue_ls doesn't work with ts_ls
  • TypeScript features stop working in Vue files
  • No autocomplete, type hints, or error highlighting
  • Editor shows "Language server initialization failed"

Fix by Editor

VSCode

Update the "Vue - Official" extension to latest version. It manages the language server automatically.

NeoVim (nvim-lspconfig)

Option 1: Use vtsls instead of ts_ls

-- Replace ts_ls/tsserver with vtsls
require('lspconfig').vtsls.setup({})
require('lspconfig').volar.setup({})

Option 2: Downgrade vue-language-server

npm install -g @vue/language-server@2.1.10

JetBrains IDEs

Update to latest Vue plugin. If issues persist, disable and re-enable the Vue plugin.

What Changed in 3.0

Feature Volar 2.x Volar 3.0
TypeScript integration ts_ls/tsserver vtsls recommended (Neovim)
Hybrid mode Optional Default

Reference: vuejs/language-tools#5598


vueCompilerOptions Overview

Option Default Effect
strictTemplates false Enables all checkUnknown* options
checkUnknownComponents false Error on undefined components
checkUnknownProps false Error on undeclared props
checkUnknownEvents false Error on undeclared events
checkUnknownDirectives false Error on unregistered directives
strictCssModules false Check CSS module class names
fallthroughAttributes false Enable IDE autocomplete for $attrs
dataAttributes [] Allow specific data-* patterns

Strict CSS Modules

When using CSS modules with <style module>, Vue doesn't validate class names by default. Enable strictCssModules to catch typos.

Problem

<script setup lang="ts">
// No error for typo in class name
</script>

<template>
  <div :class="$style.buttn">Click me</div>
</template>

<style module>
.button {
  background: blue;
}
</style>

The typo buttn instead of button silently fails at runtime.

Solution

// tsconfig.json or tsconfig.app.json
{
  "vueCompilerOptions": {
    "strictCssModules": true
  }
}

What Gets Checked

Access With strictCssModules
$style.validClass OK
$style.typo Error: Property 'typo' does not exist
$style['dynamic'] OK (dynamic access not checked)

Limitations: Only checks static property access. Dynamic access ($style[variable]) is not validated.

Reference: Vue Language Tools Wiki - Vue Compiler Options


Fallthrough Attributes

When building component libraries with wrapper components, enable fallthroughAttributes to get IDE autocomplete for attributes that will be forwarded to child elements.

What It Does

<!-- MyButton.vue - wrapper around native button -->
<template>
  <button v-bind="$attrs"><slot /></button>
</template>

Solution

// tsconfig.json or tsconfig.app.json
{
  "vueCompilerOptions": {
    "fallthroughAttributes": true
  }
}

When fallthroughAttributes: true:

  • Vue Language Server analyzes which element receives $attrs
  • IDE autocomplete suggests valid attributes for the target element

Note: This primarily enables IDE autocomplete for valid fallthrough attributes. It does NOT reject invalid attributes as type errors.

Reference: Vue Language Tools Wiki - Vue Compiler Options


Data Attributes Allowlist

With strictTemplates enabled, data-* attributes on components cause type errors. Use the dataAttributes option to allow specific patterns.

Problem

<template>
  <!-- Error: Property 'data-testid' does not exist on type... -->
  <MyComponent data-testid="submit-button" />
</template>

Solution

// tsconfig.json or tsconfig.app.json
{
  "vueCompilerOptions": {
    "strictTemplates": true,
    "dataAttributes": ["data-*"]
  }
}

Specific Patterns

You can be more selective:

{
  "vueCompilerOptions": {
    "dataAttributes": [
      "data-testid",
      "data-cy",
      "data-test-*"
    ]
  }
}

Common Testing Attributes

Library Attribute Pattern
Testing Library data-testid "data-testid"
Cypress data-cy "data-cy"
Playwright data-testid "data-testid"
Generic All data attributes "data-*"

Reference: Vue Language Tools Wiki - Vue Compiler Options


Vue Directive Comments

Vue Language Tools supports special directive comments to control type checking behavior in templates.

@vue-ignore

Suppress type errors for the next line:

<template>
  <!-- @vue-ignore -->
  <Component :prop="valueWithTypeError" />
</template>

@vue-expect-error

Assert that the next line should have a type error (useful for testing):

<template>
  <!-- @vue-expect-error -->
  <Component :invalid-prop="value" />
</template>

@vue-skip

Skip type checking for an entire block:

<template>
  <!-- @vue-skip -->
  <div>
    <!-- Everything in here is not type-checked -->
    <LegacyComponent :any="props" :go="here" />
  </div>
</template>

@vue-generic

Declare template-level generic types:

<template>
  <!-- @vue-generic {T extends string} -->
  <GenericList :items="items as T[]" />
</template>

Use Cases

  • Migrating legacy components with incomplete types
  • Working with third-party components that have incorrect type definitions
  • Temporarily suppressing errors during refactoring
  • Testing that certain patterns produce expected type errors

Reference: Vue Language Tools Wiki - Directive Comments


Code Actions Performance

In large Vue projects, saving files can take 30-60+ seconds due to VSCode's code actions triggering expensive TypeScript state synchronization.

Symptoms

  • Save operation takes 30+ seconds
  • Editor becomes unresponsive during save
  • CPU spikes when saving Vue files

Solution

Option 1: Disable code actions (fastest)

// .vscode/settings.json
{
  "vue.codeActions.enabled": false
}

Option 2: Limit code action time

// .vscode/settings.json
{
  "vue.codeActions.savingTimeLimit": 1000
}

Option 3: Disable specific code actions

// .vscode/settings.json
{
  "vue.codeActions.enabled": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": "never"
  }
}

Additional Optimizations

// .vscode/settings.json
{
  "vue.codeActions.enabled": false,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {},
  "[vue]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "Vue.volar"
  }
}

VSCode 1.81.0+ includes fixes that reduce save time issues.

Reference: Vue Language Tools Discussion #2740

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides comprehensive best practices for Vue 3 development, including TypeScript integration, component design patterns, testing strategies using Pinia and Vitest, and tooling configuration for Vite and Volar. All referenced resources and packages are standard ecosystem tools from reputable sources.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    6/6 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 6e805e4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 10 months ago
metadata
{
  "author": "ejirocodes",
  "version": "1.0.0"
}

README badge

README badge for ejirocodes/agent-skills/vue-best-practices