index.js 492 B

123456789101112131415161718192021222324252627
  1. import {
  2. createPinia
  3. } from "pinia";
  4. import piniaPersist from "pinia-plugin-persist-uni";
  5. // 自动注入所有pinia模块
  6. const files = import.meta.glob("./*.js", {
  7. eager: true
  8. });
  9. const modules = {};
  10. Object.keys(files).forEach((key) => {
  11. modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
  12. });
  13. export const setupPinia = (app) => {
  14. const pinia = createPinia();
  15. pinia.use(piniaPersist);
  16. app.use(pinia);
  17. };
  18. export default (name) => {
  19. return modules[name]();
  20. };