Middle
Pinia nedir?
sobes.tech yapay zeka
AI'dan gelen yanıt
Pinia, Vue.js için modern bir durum yönetimi kütüphanesidir ve Vuex'in yerini almıştır. Kullanımı daha basittir, daha anlaşılır bir API'ye sahiptir ve Vue 3'ün Composition API'si ile daha iyi entegre olur. Pinia, uygulamanın tüm bileşenlerinde kullanılabilecek merkezi veri depoları oluşturmayı sağlar.
Pinia mağazası oluşturma ve kullanma örneği:
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++
}
}
})
// Bileşende
import { useCounterStore } from './stores/counter'
const counter = useCounterStore()
counter.increment()
console.log(counter.count) // 1