Pinia
| Pinia | |
|---|---|
| Original author | Eduardo San Martin Morote |
| Initial release | November 2019 |
| Stable release | 2.3.1
/ 20 Jan 2025 |
| Written in | TypeScript |
| Platform | Web platform |
| Predecessor | Vuex |
| Size | ~1.5 KB |
| Type | State management library |
| License | MIT License |
| Website | pinia |
| Repository | github |
Pinia (pronounced /piːnjʌ/, or "peenya" in English) is a store library and state management framework for Vue.js.[1] Designed primarily for building front-end web applications, it uses declarative syntax and offers its own state management API. Pinia was endorsed by the Vue.js team as a credible alternative to Vuex and is currently the official state management library for Vue.[2]
Overview
Unlike Vuex, Pinia is modular by design and does not include mutations. This enables developers to create numerous stores and import them into components as needed. The framework provides a centralised store with a built-in mechanism for saving, updating and retrieving application state.[3]
History
Pinia was conceived by Vue developer Eduardo San Martin Morote[4] as an exploration of what Vuex could look like in the future.[5] This involved creating a simpler API with "less ceremony" and providing better support for type inference with TypeScript.[6] It became an official part of the Vue.js ecosystem on February 7, 2022.[5]
The store library takes its name from piña, the Spanish word for "pineapple." According to its creators, "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."[7]
Features
Store pillars
Stores in Pinia are defined via a JavaScript object with a variety of characteristics that govern their behaviour. These are regarded as the "pillars" of a store, and as shown in the code example below, include state, getters and actions.[8]
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
state: () => ({
count: 0
}),
getters: {
doubleCount: state => state.count * 2
},
actions: {
increment(amount) {
this.count += amount
}
}
})
Devtools support
Pinia integrates with Vue Devtools, a popular extension for debugging Vue.js applications.[9]
Support for plugins
The framework includes support for multiple plugins, including Nuxt and the aforementioned Devtools.[10]
Hot module replacement
Pinia allows developers to maintain existing states while writing code and to modify stores without reloading the page.
See also
References
- ^ Gerchev, Ivaylo (2022-04-11). "Complex Vue 3 state management made easy with Pinia". LogRocket Blog. Retrieved 2023-02-22.
- ^ "Build a To-do List App with Pinia and Vue 3". Deepgram. 2022-10-12. Retrieved 2023-02-22.
- ^ Jahr, Adam. "What is Pinia? - Pinia Fundamentals". Vue Mastery. Retrieved 2023-01-18.
- ^ "Pinia, an Alternative Vue.js Store - Vue School Blog". vueschool.io. Retrieved 2023-01-17.
- ^ a b Mariappan (2022-10-13). "What makes Pinia the new default?". Frontend Weekly. Retrieved 2023-01-17.
- ^ "Pinia vs. Vuex: Is Pinia a good replacement for Vuex?". DEV Community 👩💻👨💻. Retrieved 2023-02-22.
- ^ "Everything Beyond State Management in Stores with Pinia". morioh.com. Retrieved 2023-02-22.
- ^ "Pinia vs Vuex: Farewell Vuex, Hello Pinia! How to Get Started? | SPG Blog | Web Applications Development |". Software Planet Group. 2023-01-11. Retrieved 2023-01-17.
- ^ "How To Handle State Management in Vue Using Pinia - CoderPad". coderpad.io. 2023-01-27. Retrieved 2023-02-22.
- ^ "Everything Beyond State Management in Stores with Pinia by Eduardo San Martin Morote - GitNation". portal.gitnation.org. Retrieved 2023-01-18.
External links
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.