mall-app-b/peach/store/index.js

21 lines
501 B
JavaScript
Raw Normal View History

2024-05-20 01:18:27 +08:00
import { createPinia } from "pinia";
import piniaPersist from "pinia-plugin-persist-uni";
2024-04-30 17:45:03 +08:00
// 自动注入所有pinia模块
2024-05-20 01:18:27 +08:00
const files = import.meta.globEager("./*.js");
const modules = {};
2024-04-30 17:45:03 +08:00
Object.keys(files).forEach((key) => {
2024-05-20 01:18:27 +08:00
modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
});
2024-04-30 17:45:03 +08:00
export const setupPinia = (app) => {
2024-05-20 01:18:27 +08:00
const pinia = createPinia();
pinia.use(piniaPersist);
2024-04-30 17:45:03 +08:00
2024-05-20 01:18:27 +08:00
app.use(pinia);
};
2024-04-30 17:45:03 +08:00
export default (name) => {
2024-05-20 01:18:27 +08:00
return modules[name]();
};