Middle
Pinia nədir?
sobes.tech Süni İntellekt
AI-dan cavab
Pinia Vue.js üçün müasir vəziyyət idarəetmə kitabxanasıdır və Vuex-in yerini tutmuşdur. İstifadəsi daha sadədir, daha aydın API-yə malikdir və Vue 3-ün Composition API ilə daha yaxşı inteqrasiya olunur. Pinia, bütün komponentlərdə istifadə oluna biləcək mərkəzləşdirilmiş məlumat anbarları yaratmağa imkan verir.
Pinia mağazasının yaradılması və istifadəsi nümunəsi:
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++
}
}
})
// Komponentdə
import { useCounterStore } from './stores/counter'
const counter = useCounterStore()
counter.increment()
console.log(counter.count) // 1