前言
Pinia 支持使用组合式 API 来定义 store,这种方式非常符合 Vue 3 的设计理念,尤其是在处理复杂逻辑时,组合式 API 提供了更好的代码组织和复用性。
安装与引用
安装
1 | npm install pinia |
main.ts
1 | import "@/assets/css/_common.less" |
定义与使用
stores/common.ts
1 | import { ref } from 'vue' |
使用
1 | <template> |
无法显示Pinia调试工具
Vue3.0 vue.js.devtools无法显示Pinia调试工具
之前的配置方式:
1 | app.use(createPinia()) |
修改为:
1 | app.use(createPinia()).mount("#app") |
修改之后即可显示