Sobes.tech
Middle

Kas ir Pinia?

sobes.tech AI

Atbilde no AI

Pinia ir mūsdienu stāvokļa pārvaldības bibliotēka Vue.js, kas ir aizstājusi Vuex. Tā ir vienkāršāka lietošanā, tai ir saprotamāks API un tā labāk integrējas ar Vue 3 Composition API. Pinia ļauj izveidot centralizētus datu glabātuves, kuras var izmantot visās lietojumprogrammas komponentēs.

Piemērs, kā izveidot un izmantot Pinia veikalu:

import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  actions: {
    increment() {
      this.count++
    }
  }
})

// Komponentē
import { useCounterStore } from './stores/counter'

const counter = useCounterStore()
counter.increment()
console.log(counter.count) // 1