vue3-composition

Guide Vue 3 Composition API reactivity and lifecycle patterns for SSR.

3|Updated Jan 14, 2023
One-click install
npx skills add https://github.com/e-xode/vue-ssr --skill vue3-composition
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue3-composition
Source: https://github.com/e-xode/vue-ssr/tree/main/.claude/skills/vue3-composition
Command: npx skills add https://github.com/e-xode/vue-ssr --skill vue3-composition

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It resolves confusion and bugs when building Vue 3 components with the Composition API in an SSR environment, especially around ref/reactivity, lifecycle timing, and composable patterns.

Core Features & Use Cases

  • Reactivity primitives guidance: Explains when to use ref() vs reactive() (project standard: ref()), how computed() and watch() behave, and why .value and destructuring mistakes break updates.
  • Lifecycle & SSR-safe patterns: Clarifies what runs on server vs client and ensures browser-only logic (DOM, window, document, localStorage) is placed in onMounted() with proper guards.
  • Composable authoring conventions: Standardizes useXxx composable structure, returning reactive state plus methods, and keeping watchers explicit (no watchEffect()).
  • <script setup> component syntax: Covers defineProps, defineEmits, defineModel, template refs, and common patterns for focusing DOM elements after render.

Quick Start

Ask: “How should I implement an SSR-safe composable that watches the route param id and fetches data when it changes, using the project’s ref() and watch() conventions?”

Frequently Asked Questions about vue3-composition

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

FAQPage Schema
How do I write an SSR-safe composable in Vue 3 that watches route params and fetches data on change?

To write an SSR-safe Vue 3 composable, use `ref()` for state and explicit `watch()` for route param changes, ensuring browser-only logic like data fetching guards are placed inside `onMounted()` to prevent server-side execution errors.

Why does my Vue 3 component reactivity break when destructuring reactive state in script setup?

Vue 3 reactivity breaks on destructuring because it loses the reactive reference. You must use `ref()` exclusively and access state via `.value` to maintain reactivity, avoiding `reactive()` and the implicit tracking of `watchEffect()`.

What is the best way to handle browser-only APIs like localStorage in Vue 3 SSR applications?

The best way to handle browser-only APIs in Vue 3 SSR is to wrap `window`, `document`, or `localStorage` access inside `onMounted()` lifecycle hooks with proper guards, ensuring this code only executes on the client.

When do I need to use ref() instead of reactive() for Vue 3 Composition API state management?

You need to use `ref()` instead of `reactive()` as the project standard for Vue 3 Composition API state management to avoid destructuring issues and ensure `.value` access maintains consistent reactivity across SSR and client environments.

Does Vue 3 script setup support defineModel and template refs for focusing DOM elements after render?

Yes, Vue 3 `<script setup>` supports `defineModel` for two-way binding and template refs to focus DOM elements after render, requiring SSR-safe guards to ensure DOM access logic only runs during client-side `onMounted()`.

What are the limitations of using watchEffect() in Vue 3 SSR composable patterns?

The limitation of `watchEffect()` in Vue 3 SSR composable patterns is its implicit dependency tracking, which can cause unexpected server-side execution; explicit `watch()` is enforced to ensure reactivity behaves safely across server and client.