Installing Pinia
To use Pinia in a Vue application, you’ve got two ways to add it. First, when creating a new Vue application via the standard method (npm init vue@latest
), one of the questions asked will be whether you wish to include Pinia. Simply say Yes here:

Figure 10.2 – Indicating whether you wish to add Pinia to a new Vue project
If you have an existing Vue 3 application, adding support is nearly as easy. First, in the project, add Pinia via npm
: npm install pinia
. Next, you need to include Pinia in the application. Your main.js
file (located in the /src
directory) will look like so:
import { createApp } from 'vue' import App from './App.vue' createApp(App).mount('#app')
Begin by importing Pinia:
import { createApp } from 'vue' import { createPinia } from 'pinia' import App from './App.vue' createApp(App).mount('#app')
Then, modify the createApp
line...