Skip to content

Vue State Management

Local component state first; Pinia for shared client state; URL for shareable filters. This lesson covers practical patterns, syntax, and mistakes to avoid.

Choosing State Tools

Local component state first; Pinia for shared client state; URL for shareable filters.

Vuex is legacy for new Vue 3 apps but still appears in older code.

// Prefer Pinia stores for shared client state
// Prefer dedicated data libraries for server cache

Match tool to data type.

Layers

local refs, props, pinia, route query, server cache
  • Prefer Composition API + script setup.
  • Use computed for derived UI.
  • Keep side effects intentional.
  • Practice in a small Vite app.

Vue State Management Cheatsheet

Quick reference for patterns covered in this lesson.

Item Example Purpose
local ref Default
pinia shared Client
vuex legacy Old
route URL state Share
provide subtree Inject
avoid globalize UI-only Smell

Server vs Client

Do not force list caching only into Pinia without a strategy.

Common Mistakes

  • One mega store.
  • Duplicating route state into Pinia needlessly.

Key Takeaways

  • Vue State Management is important in Vue apps.
  • Practice in SFCs.
  • Prefer clear naming.
  • Check Vue docs for details.

Pro Tip

If refresh should restore UI, put it in the URL.