Код IT
← Каталог

Справочник по Vue.js — Pinia (официальная библиотека для Vue 3)

Фрагмент из «Справочник по Vue.js»: Pinia (официальная библиотека для Vue 3).

javascript javascriptencyclopedia3-ecosystem-2-frontend-frameworks-2-vue-281 embed URL статья в энциклопедии
JavaScript main.js

import { defineStore } from 'pinia'

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

import { defineStore } from 'pinia'

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