Intuitive
Intuitive API that makes state management simple and clear. No complex boilerplate code, focus on business logic.
Type Safe, Extensible, and Modular by design. Forget you are even using a store.
npm install pinia
yarn add pinia
pnpm add pinia
// main.js
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
const app = createApp(App)
app.use(createPinia())
app.mount('#app')
// stores/counter.js
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
state: () => ({
count: 0
}),
getters: {
doubleCount: (state) => state.count * 2
},
actions: {
increment() {
this.count++
}
}
})
<!-- Use in component -->
<template>
<div>
<p>Count: {{ counter.count }}</p>
<p>Double Count: {{ counter.doubleCount }}</p>
<button @click="counter.increment()">Increment</button>
</div>
</template>
<script setup>
import { useCounterStore } from '@/stores/counter'
const counter = useCounterStore()
</script>
Pinia is the official state management library for Vue.js, providing a simpler and more intuitive API while maintaining powerful functionality:
Ready to get started? Check out our Getting Started Guide or learn about Pinia's Core Concepts.