const init = (params) => { console.log('moduleA init'); return { name: 'ModuleA', functionName: params.type, otherParams: { id: `xxxx${params.type}`, age: `xxxx${params.type}`, }, }; }; const getData = (params) => { console.log('moduleA getData'); return { name: 'ModuleA', functionName: params.type, otherParams: { id: `xxxx${params.type}`, age: `xxxx${params.type}`, }, }; }; // 创建函数映射对象 const functionMap = { init, getData, }; export default function (params) { // console.log('moduleA'); // console.log(params); // 方式一(打包时因为没有调用init, getData方法,所以会删除导致报错,改为方式二就没问题) // return eval(params.type + '(params)'); // 方式二 return functionMap[params.type](params); }