How to install Pinia using npm

In a Vuejs project, you might be familiar with state management using Vuex. Pinia is the new store to manage the application state in Vuejs. Your app can still use events and props and/or Vuex and Composition API for state management.

State management in Pinia is a single data source and store for your application. It can include data from other sources as well, for example from Firebase, or across different components in the app. It uses methods to track and manage changes to state component-wise. It gathers data and you can access it by reading and writing at Pinia.

So, this is how to install Pinia using npm in your Vuejs project:

  • In the root directory, type:
npm install pinia
  • In your main.js file, create the root store (pinia), and pass it to the app to enable it for the application:
import { createPinia } from 'pinia'
...
app.use(createPinia())

Enjoy coding!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store