index.ts 478 B

123456789101112131415161718192021222324
  1. import type { App } from 'vue';
  2. import type { Pinia } from 'pinia';
  3. import { createPinia } from 'pinia';
  4. let app: Nullable<App<Element>> = null;
  5. let store: Nullable<Pinia> = null;
  6. export function setupStore($app: App<Element>) {
  7. if (store == null) {
  8. store = createPinia();
  9. }
  10. app = $app;
  11. app.use(store);
  12. }
  13. // 销毁store
  14. export function destroyStore() {
  15. store = null;
  16. }
  17. // 获取app实例
  18. export const getAppContext = () => app?._context;
  19. export {app, store};