VUE3引入pinia配置使用

文档:https://pinia.vuejs.org/zh/introduction.html

1.引入pinna

npm install pinia -S

2.在src文件里面创建store文件article.js 在main.js中引用pinna

复制代码

import { defineStore } from 'pinia'

// 你可以对 `defineStore()` 的返回值进行任意命名,但最好使用 store 的名字,同时以 `use` 开头且以 `Store` 结尾。(比如 `useUserStore`,`useCartStore`,`useProductStore`)
// 第一个参数是你的应用中 Store 的唯一 ID。
export const useAlertsStore = defineStore('alerts', {
// 其他配置...
})

复制代码

 获取多个接口

 使用pinia

import { useArticleStore } from "@/stores/article";
const articleOther = useArticleStore();

 

posted @   SHACK元  阅读(190)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示