import { createPinia } from 'pinia'
import piniaPersist from 'pinia-plugin-persist-uni'
// 自动注入所有pinia模块
const files = import.meta.globEager('./*.js')
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]()
}
- 发布:2024-05-29 23:42
- 更新:2024-12-18 23:44
- 阅读:455
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows 11 Pro 23H2
HBuilderX类型: 正式
HBuilderX版本号: 4.15
第三方开发者工具版本号: 1.06.2405282
基础库版本号: 3.4.3
项目创建方式: HBuilderX
操作步骤:
预期结果:
"use strict";
const peach_store_app = require("./app.js");
const peach_store_modal = require("./modal.js");
const peach_store_sys = require("./sys.js");
const peach_store_user = require("./user.js");
const common_vendor = require("../../common/vendor.js");
const files = /* @__PURE__ */ Object.assign({ "./app.js": peach_store_app.__vite_glob_0_0, "./modal.js": peach_store_modal.__vite_glob_0_1, "./sys.js": peach_store_sys.__vite_glob_0_2, "./user.js": peach_store_user.__vite_glob_0_3 });
const modules = {};
Object.keys(files).forEach((key) => {
modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
});
const setupPinia = (app) => {
const pinia = common_vendor.createPinia();
pinia.use(common_vendor.index$1);
app.use(pinia);
};
const $store = (name) => {
return modules[name]();
};
exports.$store = $store;
exports.setupPinia = setupPinia;
"use strict";
const peach_store_app = require("./app.js");
const peach_store_modal = require("./modal.js");
const peach_store_sys = require("./sys.js");
const peach_store_user = require("./user.js");
const common_vendor = require("../../common/vendor.js");
const files = /* @__PURE__ */ Object.assign({ "./app.js": peach_store_app.__vite_glob_0_0, "./modal.js": peach_store_modal.__vite_glob_0_1, "./sys.js": peach_store_sys.__vite_glob_0_2, "./user.js": peach_store_user.__vite_glob_0_3 });
const modules = {};
Object.keys(files).forEach((key) => {
modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
});
const setupPinia = (app) => {
const pinia = common_vendor.createPinia();
pinia.use(common_vendor.index$1);
app.use(pinia);
};
const $store = (name) => {
return modules[name]();
};
exports.$store = $store;
exports.setupPinia = setupPinia;
实际结果:
"use strict";
const common_vendor = require("../../common/vendor.js");
const files = (void 0)("./*.js");
const modules = {};
Object.keys(files).forEach((key) => {
modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
});
const setupPinia = (app) => {
const pinia = common_vendor.createPinia();
pinia.use(common_vendor.index$1);
app.use(pinia);
};
const $store = (name) => {
return modules[name]();
};
exports.$store = $store;
exports.setupPinia = setupPinia;
"use strict";
const common_vendor = require("../../common/vendor.js");
const files = (void 0)("./*.js");
const modules = {};
Object.keys(files).forEach((key) => {
modules[key.replace(/(.*\/)*([^.]+).*/gi, "$2")] = files[key].default;
});
const setupPinia = (app) => {
const pinia = common_vendor.createPinia();
pinia.use(common_vendor.index$1);
app.use(pinia);
};
const $store = (name) => {
return modules[name]();
};
exports.$store = $store;
exports.setupPinia = setupPinia;
bug描述:
使用 import.meta.globEager 导入当前目录下的 .js 文件
HBuilderX 4.08 正常编译微信小程序,代码正常运行,转译结果为下面预期结果内容
HBuilderX 4.15 编译微信小程序后,代码如下面实际结果所示,提示 void 0 not a function
4 个回复
Emp默
我页遇到了
ero
import { isFunction } from '@vue/shared'
import { App } from 'vue'
const modules = import.meta.globEager('./modules/*/.ts')
export default {
install: (app: App) => {
for (const module of Object.values(modules)) {
const fun = module.default
isFunction(fun) && fun(app)
}
}
}
ero
我的也报错、
ero
手机端报这个
23:43:45.693 reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught TypeError: (void 0) is not a function
at (app-service.js:96161:27)
at (app-service.js:96267:3)