pinia之组件外使用store
发布日期:2023-09-18 22:10:16 浏览次数:3 分类:技术文章

本文共 770 字,大约阅读时间需要 2 分钟。

在ts文件中使用pinia(getActivePinia was called with no active Pinia. Did you forget to install pinia)报错解决

一、创建store.ts文件

import { createPinia } from "pinia";const store = createPinia();export default store

二、在main.ts中引入

// main.tsimport App from "./App.vue";import pinia from "@/store/index";    // 引入创建好的piniaapp.use(pinia);  // 使用piniaapp.mount("#app");

三、创建自己的pinia文件

import { defineStore } from "pinia";interface State {nodeArr: any[] | [];stencilLoading: boolean;selectNodeId: number;lcNodeData: LCDataType | {}}export const useMenuListStore = defineStore("menuListStore", ()=>{    });

四、在ts文件中使用pinia

import { useMenuListStore } from "@/store/useMenuList";import store from "@/store/index";const menuListStore = useMenuListStore (store);// 此时就可以使用 menuListStore 身上的属性和方法了

转载地址:https://blog.csdn.net/m0_58575070/article/details/132536478 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:上海岛安科技中心
下一篇:pinia 持久化插件 pinia-plugin-persistedstate 使用

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2023年09月24日 11时33分38秒