index.js 493 B

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