使用 Pinia
Pinia 是 Vue 的官方状态管理库。它提供了类型安全、可扩展且模块化的 store,API 基于组合式 API 构建,使用起来非常直观。
另请参阅:Vue.js — 状态管理
安装
设置
将 Pinia 注册到你的 vue-lynx 应用中:
src/index.ts
定义 Store
使用 defineStore 配合 setup 语法 来创建 store:
src/stores/counter.ts
在组件中使用 Store
src/CounterSection.vue
查看 Pinia — 核心概念 了解更多资源。