跳到正文
Skillpedia
网站与界面(前端)6.0k · #14448

vue

它能做什么

这项技能说明如何使用现代的 Composition API 和 TypeScript 构建 Vue 3 用户界面。适合用 Vue 制作网页和应用的开发者。

适用场景

  • ✓当你在编写或编辑 Vue 单文件组件时。
  • ✓当你需要定义组件的 props、emits 或双向 model 时。
  • ✓当你想使用过渡、侦听器或 Teleport 等内置组件的时候。

技能链接

https://github.com/antfu/skills/blob/main/skills/vue/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/antfu/skills/blob/main/skills/vue/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请为搜索框构建一个 Vue 组件,让它在输入时发出输入的文字,并显示清除按钮。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体遵循 Vue 3 的 Composition API 风格,结合 script setup 和 TypeScript,使用当前的响应式工具,并保持数据处理简单高效。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Vue

Based on Vue 3.5, generated at 2026-09-25. Always use Composition API with <script setup lang="ts">.

Preferences

  • Prefer TypeScript over JavaScript
  • Prefer <script setup lang="ts"> over <script>
  • For performance, prefer shallowRef over ref if 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

Component Template

<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'

const props = defineProps<{
  title: string
  count?: number
}>()

const emit = defineEmits<{
  update: [value: string]
}>()

const model = defineModel<string>()

const doubled = computed(() => (props.count ?? 0) * 2)

watch(() => props.title, (newVal) => {
  console.log('Title changed:', newVal)
})

onMounted(() => {
  console.log('Component mounted')
})
</script>

<template>
  <div>{{ title }} - {{ doubled }}</div>
</template>

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'
常见问题

它使用 Options API 吗?

不使用。它推荐使用 Composition API,而不是 Options API。

它推荐哪种脚本写法?

它推荐使用带 lang ts 的 script setup,这样组件简短,并且有类型。

它涵盖内置组件吗?

涵盖。它包括 Transition、Teleport、Suspense 和 KeepAlive。

详情

作者的原始描述

Vue 3 Composition API, script setup macros, reactivity system, and built-in components. Use when writing Vue SFCs, defineProps/defineEmits/defineModel, watchers, or using Transition/Teleport/Suspense/KeepAlive.

repo: antfu/skills

热度

GitHub 星标
6.0k
排名
#14448
许可证
MIT
更新时间
2026/10/30

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能