Pinia
存储库
Pinia 是 Vue 的存储库
Pinia
属性 state
, getters
, actions
基本示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => { return { count: 0 } }, actions: { increment() { this.count++ }, }, })
import { useCounterStore } from '@/stores/counter' export default { setup() { const counter = useCounterStore()
counter.count++ counter.$patch({ count: counter.count + 1 }) counter.increment() }, }
|
其他
pinia状态管理