Install and use Pinia in Vue.

Pinia is a store library for Vue, it allows you to share a state across components/pages.

To install pinia type this in command prompt.

npm install pinia

After installing pinia, enter the script in main.js file

import { createPinia } from 'pinia';
const pinia = createPinia()
app.use(pinia);

Given is the Javascript sample of pinia


import { defineStore } from "pinia";
export const useGlobalStore = defineStore({
    id: "globalValues",
    state: () => ({
        userData: {},
        claimDetails: []
    }),
    actions: {
        getUserData(objData) {
            this.userData = objData
        },
        getClaimDetails(apiResult) {
            this.claimDetails = apiResult;
    },
});

Leave a comment

Your email address will not be published. Required fields are marked *