vue
Vue
Based on Vue 3.5. Always use Composition API with
<script setup>.
Preferences
- Prefer JavaScript over TypeScript
- Prefer
<script setup>over<script setup lang="ts"> - Strictly follow the
<template>tag at the top, the<script>tag in the middle, and the<style>tag at the bottom. - For performance, prefer
shallowRefoverrefif deep reactivity is not needed - Always use Composition API over Options API
- Discourage using Reactive Props Destructure
Core
| Topic | Description | Reference |
|---|---|---|
| Script Setup & Macros | <script setup>, defineProps, defineEmits, defineModel, defineExpose, defineOptions, defineSlots, generics |
script-setup-macros |
| Reactivity & Lifecycle | ref, shallowRef, computed, watch, watchEffect, effectScope, lifecycle hooks, composables | core-new-apis |
Features
| Topic | Description | Reference |
|---|---|---|
| Built-in Components & Directives | Transition, Teleport, Suspense, KeepAlive, v-memo, custom directives | advanced-patterns |
Quick Reference
Page Structure Convention (Mandatory)
When generating a new Vue page, ALWAYS use a folder-per-page structure:
src/views/<page-name>/index.vue
Rules:
<page-name>must be kebab-case.- NEVER create pages directly under
src/viewsas a single file (forbidden:src/views/home.vue). - If the user only provides a page name (without a path), infer and create the folder structure automatically.
- Place related files in the same folder when needed (e.g.
index.ts,types.ts,style.scss,__tests__).
Example:
- Request: "Create Home page" or "Create AboutMe page"
- Output path:
src/views/home/index.vueorsrc/views/about-me/index.vue - Not allowed:
src/views/home.vueorsrc/views/about-me.vue
Component Structure Convention (Mandatory)
When generating a new Vue component, ALWAYS use a folder-per-component structure:
src/components/<ComponentName>/<ComponentName>.vue
Rules:
<ComponentName>must be PascalCase.- NEVER create components directly under
src/componentsas a single file (forbidden:src/components/HelloWorld.vue). - If the user only provides a component name (without a path), infer and create the folder structure automatically.
- Place related files in the same folder when needed (e.g.
index.ts,types.ts,style.scss,__tests__).
Example:
- Request: "Create HelloWorld component"
- Output path:
src/components/HelloWorld/HelloWorld.vue - Not allowed:
src/components/HelloWorld.vue
Component Template
<template>
<div>{{ title }} - {{ count }}</div>
</template>
<script setup>
import { ref, computed, watch, onMounted } from 'vue'
const props = defineProps({
title: {
type: String,
default: 'Hello Vue'
}
})
const emit = defineEmits(['change'])
const count = defineModel('value', {
type: Number,
default: 0
})
watch(
() => props.title,
(newVal) => {
console.log('Title:', newVal)
}
)
onMounted(() => {
console.log('Component mounted')
})
</script>
<style lang="scss" scoped></style>
Key Imports
// Reactivity
import { ref, shallowRef, computed, reactive, readonly, toRef, toRefs, toValue } from 'vue'
// Watchers
import { watch, watchEffect, watchPostEffect, onWatcherCleanup } from 'vue'
// Lifecycle
import { onMounted, onUpdated, onUnmounted, onBeforeMount, onBeforeUpdate, onBeforeUnmount } from 'vue'
// Utilities
import { nextTick, defineComponent, defineAsyncComponent } from 'vue'
More from sonvee/ai-skills
my-coding-style
编码时必须严格遵循我的编码风格,编码时应优先使用该技能,在写文档时不使用该技能
10fullstack-init
初始化前后端分离全栈项目的脚手架和配置,并在日常开发中遵守用户固定的技术栈选型。当用户提到"初始化项目"、"新建全栈项目"、"搭建前后端分离项目"、"创建一个新项目"、"帮我建个项目"等意图时,主动触发此 skill。即使用户没有明确说"全栈",只要上下文涉及同时需要前端和后端的新项目,也应触发。日常讨论技术方案、写代码时也应遵守本 skill 中的技术栈约定。
8vueuse-functions
Apply VueUse composables where appropriate to build concise, maintainable Vue.js / Nuxt features.
7vue-best-practices
MUST be used for Vue.js tasks. Strongly recommends Composition API with `<script setup>` and TypeScript as the standard approach. Covers Vue 3, SSR, Volar, vue-tsc. Load for any Vue, .vue files, Vue Router, Pinia, or Vite with Vue work. ALWAYS use Composition API unless the project explicitly requires Options API.
7vite
Vite build tool configuration, plugin API, SSR, and Vite 8 Rolldown migration. Use when working with Vite projects, vite.config.ts, Vite plugins, or building libraries/SSR apps with Vite.
7vitest
Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.
7