Socket
Socket
Sign inDemoInstall

pinia

Package Overview
Dependencies
24
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pinia

Intuitive, type safe and flexible Store for Vue


Version published
Maintainers
1
Install size
427 kB
Created

Package description

What is pinia?

Pinia is a state management library for Vue.js applications. It serves as a store for shared state, with a simple and straightforward API. It is often used as an alternative to Vuex and provides reactive data stores that can be accessed throughout a Vue application.

What are pinia's main functionalities?

Defining a Store

This feature allows you to define a new store with a unique identifier, state, and actions. The state is reactive and can be accessed and manipulated across components.

import { defineStore } from 'pinia';

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0
  }),
  actions: {
    increment() {
      this.count++;
    }
  }
});

Accessing Store State in Components

This code demonstrates how to access and use the store state within a Vue component. The store's reactive state is used in the template, and actions can be called to update the state.

<template>
  <div>{{ counterStore.count }}</div>
  <button @click="counterStore.increment">Increment</button>
</template>

<script setup>
import { useCounterStore } from './stores/counter';

const counterStore = useCounterStore();
</script>

Persisting State

Pinia allows for easy integration with other libraries, such as VueUse, to persist state between page reloads using local storage or other methods.

import { defineStore } from 'pinia';
import { useLocalStorage } from '@vueuse/core';

export const useUserStore = defineStore('user', {
  state: () => ({
    name: useLocalStorage('user-name', '')
  })
});

Other packages similar to pinia

Readme

Source

Pinia logo

Pinia

Intuitive, type safe and flexible Store for Vue

👉 Demo with Vue 3 on StackBlitz

Help me keep working on this project 💚

Documentation

To learn more about Pinia, check its documentation.

License

MIT

Keywords

FAQs

Last updated on 14 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc