Creating a Pinia Store
📖 Scenario: You are building a simple Vue 3 app that needs to share a counter value across components. To do this, you will create a Pinia store to hold and manage the counter state.
🎯 Goal: Build a Pinia store named useCounterStore that holds a count state starting at 0, a getter to get the double of count, and an action to increment count by 1.
📋 What You'll Learn
Create a Pinia store using
defineStore.Store must have a state with a
count property initialized to 0.Add a getter named
doubleCount that returns count * 2.Add an action named
increment that increases count by 1.💡 Why This Matters
🌍 Real World
Pinia stores help manage shared state in Vue apps, making it easy to keep data consistent across components.
💼 Career
Understanding Pinia is important for Vue developers to build scalable and maintainable applications.
Progress0 / 4 steps