vue

Write Vue 3 components using Composition API and script setup.

Updated Apr 6, 2022
One-click install
npx skills add https://github.com/wjyugutou/study-test-demo --skill vue-wjyugutou
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue
Source: https://github.com/wjyugutou/study-test-demo/tree/main/.trae/skills/vue
Command: npx skills add https://github.com/wjyugutou/study-test-demo --skill vue-wjyugutou

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill guides developers to write Vue 3 components with the Composition API and script setup, delivering concise, typesafe components that are easier to maintain and reason about.

Core Features & Use Cases

  • Composition API-centric component design with setup(), refs, reactive, computed, and lifecycle hooks.
  • Script setup macros such as defineProps, defineEmits, defineModel, and defineExpose for streamlined prop and event handling.
  • Use cases include building scalable SFCs, migrating from Options API, and documenting Vue best practices across teams.

Quick Start

Install and start a Vue project, then create a component using <script setup lang="ts">, defineProps/defineEmits, and basic refs to manage state.

Frequently Asked Questions about vue

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Vue 3 components using script setup and the Composition API?

To write Vue 3 components using script setup, use the `<script setup>` macro to leverage the Composition API. This approach simplifies reactive state management and component logic by directly utilizing refs, computed properties, and lifecycle hooks within your SFCs.

What is the best way to define props and emit events in Vue 3 SFCs?

The best way to define props and emit events in Vue 3 SFCs is using the `defineProps` and `defineEmits` compiler macros. These macros provide a type-safe, modular approach to handling component inputs and outputs directly within the script setup block.

How does defineModel work for two-way binding in Vue 3?

The `defineModel` macro streamlines two-way binding in Vue 3 by automatically managing the reactive state and event emissions for a component's v-model. It creates a concise, type-safe reference that simplifies parent-child data synchronization.

Can I migrate my existing Options API components to the Composition API?

Yes, you can migrate existing Options API components to the Composition API. This transition involves restructuring data, methods, and lifecycle hooks into modular setup functions using refs, reactive objects, and script setup macros for improved maintainability.

Why should I use the Composition API over the Options API in Vue projects?

You should use the Composition API over the Options API to achieve better logic organization and reusability. It allows you to group related reactive state, computed properties, and lifecycle hooks together, making complex Vue 3 components easier to maintain and reason about.

How do I expose component methods to parent components when using script setup?

To expose component methods to parent components when using script setup, utilize the `defineExpose` macro. This explicitly declares the internal properties and functions that parent components can access via template refs, ensuring controlled encapsulation.