Install Pinia Manually
- Note:
The best way to install vue router on a new project is to install it as part of the setup.
These notes are useful for if you need to add it to an existing project that does not include it.
If the project is running press ctrl + c to stop it
Enter the following in the command line to install the latest version of vue router -
Update main.js
In the main.js file add the following to import Pinia -
And then add the using statement to the createApp method -
Add a Store
Create a new folder within the src folder called stores
Then add a JS file with an appropriate name for your store (e.g. storeNotes.js)
Add a import statement and then add the scaffolding for the store, the official website has an example that can be copied -
- Note:
Official website guide -
Pinia
Then update the names used as appropriate and remove the example methods -
Add data to the store -
Use the Store
Within the component file you wish to access the stores data from, add an import statement -
Then create a new const and assign it to the store -
You should now be able to see the store on the page using the vue dev tools