更像原先的 vuex
// src/stores/counter.jsimport { defineStore } from 'pinia'export const useCounterStore = defineStore('counterStore', { state: ()=> { return {j: 0, k: 0} }})// Counter.vueimport { useCounterStore } from 'path/to/src/stores/counterStore'export default { setup() { const counterStore = useCounterStore() // TODO 默认情况下可以直接这么更改,但是不保举 // https://pinia.vuejs.org/core-concepts/state.html#accessing-the-state counterStore.j ++ // 这里在视图里利用 counterStore.j 和 counterStore.k // 但你不能解构 counterStore,只能像下面如许解构: const { j, k } = storeToRefs(counterStore) // 注意:这里会自动忽略 方法 和 非相应式数据(Creates an object of references with all the state, getters, and plugin-added state properties of the store. Similar to toRefs() but specifically designed for Pinia stores so methods and non reactive properties are completely ignored.) return { counterStore, j, k, } },}Store Getters