All Projects → vuejs → pinia

vuejs / pinia

Licence: MIT license
🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support

Programming Languages

typescript
32286 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to pinia

vue-unstated
A tiny state management library for Vue Composition API.
Stars: ✭ 30 (-99.7%)
Mutual labels:  store, composition-api
Online-Shop-eCommerce-App-Angular-6-Firebase
Online eCommerce Store app in Angular 11.0 & Firebase
Stars: ✭ 96 (-99.04%)
Mutual labels:  store
Uploadcare Widget
Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
Stars: ✭ 183 (-98.16%)
Mutual labels:  store
Presences
🛒 Storage for Presences located at our Presence Store.
Stars: ✭ 223 (-97.76%)
Mutual labels:  store
Reto
Flexible and efficient React Store with hooks.
Stars: ✭ 194 (-98.05%)
Mutual labels:  store
Vuex Mock Store
✅Simple and straightforward Vuex Store mock for vue-test-utils
Stars: ✭ 246 (-97.53%)
Mutual labels:  store
General Store
Simple, flexible store implementation for Flux. #hubspot-open-source
Stars: ✭ 171 (-98.28%)
Mutual labels:  store
rust-json-file-store
A simple JSON file store written in Rust.
Stars: ✭ 61 (-99.39%)
Mutual labels:  store
2019-ncov-vue3-version
新型冠状病毒实时疫情 Vue-Compostion-Api版本 (Vue3 + TypeScript)
Stars: ✭ 55 (-99.45%)
Mutual labels:  composition-api
Apple Store Helper
Apple Store iPhone预约助手
Stars: ✭ 215 (-97.84%)
Mutual labels:  store
Redux Subscriber
Subscribe to changes in any part of redux state
Stars: ✭ 205 (-97.94%)
Mutual labels:  store
Flooks
🍸 A state manager for React Hooks
Stars: ✭ 201 (-97.98%)
Mutual labels:  store
Depot.js
📦 depot.js is a storage library with a simple API
Stars: ✭ 247 (-97.52%)
Mutual labels:  store
Vue Vant Store
基于vue,vantUI的商城demo,包含前端和后端
Stars: ✭ 187 (-98.12%)
Mutual labels:  store
vuex-hooks
Typescript enabled vuex composition-api hooks
Stars: ✭ 12 (-99.88%)
Mutual labels:  composition-api
Fluttergames
Flutter app for purchasing and renting games.
Stars: ✭ 182 (-98.17%)
Mutual labels:  store
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (-97.95%)
Mutual labels:  store
Vuex Easy Firestore
Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
Stars: ✭ 224 (-97.75%)
Mutual labels:  store
ZXDataHandle
简单易用的数据转换和存储框架,支持一行代码将模型、模型数组、Json字符串、字典互转;支持模型映射到sqlite3数据库,无需书写sql
Stars: ✭ 13 (-99.87%)
Mutual labels:  store
EnderFramework
EnderFramework is a framework that can be used to create apps using HTML, JS, and CSS.
Stars: ✭ 19 (-99.81%)
Mutual labels:  store

Pinia logo


npm package build status code coverage


Pinia

Intuitive, type safe and flexible Store for Vue

  • 💡 Intuitive
  • 🔑 Type Safe
  • ⚙️ Devtools support
  • 🔌 Extensible
  • 🏗 Modular by design
  • 📦 Extremely light

Pinia works with both Vue 2 and Vue 3.

Pinia is the most similar English pronunciation of the word pineapple in Spanish: piña. A pineapple is in reality a group of individual flowers that join together to create a multiple fruit. Similar to stores, each one is born individually, but they are all connected at the end. It's also a delicious tropical fruit indigenous to South America.

👉 Demo with Vue 3 on StackBlitz

👉 Demo with Nuxt 3 on StackBlitz

Help me keep working on this project 💚

Gold Sponsors

VueJobs

Silver Sponsors

VueMastery Prefect

Bronze Sponsors

Stanislas Ormières Antony Konstantinidis Storyblok NuxtJS


FAQ

A few notes about the project and possible questions:

Q: Is Pinia the successor of Vuex?

A: Yes

Q: What about dynamic modules?

A: Dynamic modules are not type safe, so instead we allow creating different stores that can be imported anywhere

Installation

# or pnpm or yarn
npm install pinia

If you are using Vue <2.7, make sure to install latest @vue/composition-api:

npm install pinia @vue/composition-api

Usage

Install the plugin

Create a pinia (the root store) and pass it to app:

// Vue 3
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'

const pinia = createPinia()
const app = createApp(App)

app.use(pinia)
app.mount('#app')
// Vue 2
import { createPinia, PiniaVuePlugin } from 'pinia'

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

new Vue({
  el: '#app',
  // other options...
  // ...
  // note the same `pinia` instance can be used across multiple Vue apps on
  // the same page
  pinia,
})

Create a Store

You can create as many stores as you want, and they should each exist in different files:

import { defineStore } from 'pinia'

// main is the name of the store. It is unique across your application
// and will appear in devtools
export const useMainStore = defineStore('main', {
  // a function that returns a fresh state
  state: () => ({
    counter: 0,
    name: 'Eduardo',
  }),
  // optional getters
  getters: {
    // getters receive the state as first parameter
    doubleCounter: (state) => state.counter * 2,
    // use getters in other getters
    doubleCounterPlusOne(): number {
      return this.doubleCounter + 1
    },
  },
  // optional actions
  actions: {
    reset() {
      // `this` is the store instance
      this.counter = 0
    },
  },
})

defineStore returns a function that has to be called to get access to the store:

import { useMainStore } from '@/stores/main'
import { storeToRefs } from 'pinia'

export default defineComponent({
  setup() {
    const main = useMainStore()

    // extract specific store properties
    const { counter, doubleCounter } = storeToRefs(main)

    return {
      // gives access to the whole store in the template
      main,
      // gives access only to specific state or getter
      counter,
      doubleCounter,
    }
  },
})

Documentation

To learn more about Pinia, check its documentation.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].