In this episode, we dive right into setting up a Pinia store in our Vue project. First off, we install Pinia using npm and wire it up in our main application file (app.js) to ensure it's available everywhere in our app.
Then we walk through creating a dedicated directory (like store/
or state/
) for our store files, following best practices for organizing state management logic. Inside, we create our first store using a composable pattern and Pinia's defineStore
function. We give our store a name (in this case, "messages") and structure it with basic state, getters, and (eventually) actions.
You’ll see how to define simple state—like an array of messages—and add a getter to neatly retrieve all messages from the state. Next, we import and use the store in one of our Vue components, making sure to invoke it as a composable so we get access to that reactive store data.
Finally, we test things out by outputting the (currently empty) messages array in our app, and discuss how actions will later be used to handle updates, like adding new messages. By the end of this episode, your Pinia store scaffolding will be up and running, ready to manage and display your app's state!