2022-11-22 07:45:36 +00:00
|
|
|
import { createPinia } from 'pinia';
|
|
|
|
import piniaPersist from 'pinia-plugin-persist-uni';
|
|
|
|
|
|
|
|
// 自动注入所有pinia模块
|
2024-05-02 01:39:00 +00:00
|
|
|
const files = import.meta.glob('./*.js', { eager: true });
|
2022-11-22 07:45:36 +00:00
|
|
|
const modules = {};
|
|
|
|
Object.keys(files).forEach((key) => {
|
|
|
|
modules[key.replace(/(.*\/)*([^.]+).*/gi, '$2')] = files[key].default;
|
|
|
|
});
|
|
|
|
|
|
|
|
export const setupPinia = (app) => {
|
|
|
|
const pinia = createPinia();
|
|
|
|
pinia.use(piniaPersist);
|
|
|
|
|
|
|
|
app.use(pinia);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (name) => {
|
|
|
|
return modules[name]();
|
|
|
|
};
|