Using stores in components
📖 Scenario: You are building a simple Vue 3 app that tracks a user's favorite color using a store. The store holds the color value and lets components read and update it.
🎯 Goal: Create a Vue 3 component that uses a store to display and update the favorite color. The component will show the current color and have a button to change it.
📋 What You'll Learn
Create a Pinia store with a state variable
favoriteColor set to 'blue'Add a function in the store called
changeColor that sets favoriteColor to 'red'Create a Vue component that imports and uses the store
Display the current
favoriteColor in the componentAdd a button in the component that calls
changeColor when clicked💡 Why This Matters
🌍 Real World
Stores help manage shared data in Vue apps, like user preferences or app settings, so components stay in sync easily.
💼 Career
Understanding how to use Pinia stores is important for Vue developers to build scalable and maintainable applications.
Progress0 / 4 steps