javascript 为什么使用索引文件时导出在Webpack中失败

x33g5p2x  于 2023-03-11  发布在  Java
关注(0)|答案(1)|浏览(116)

常量文件中的文件

export const localStorageItem = {      
  COMPANY_ID: "companyId",
  COMPANY_NAME: "companyName",
  LANDING_PAGE: "landingPage",
  LOGIN_TYPE: "loginType",
  PLATFORM_VERSION: "platformVersion",
  PLATFORM_VIEWS: "platformViews"      
};

常量文件夹中的索引文件

...
export * from "./design.constant";
export * from "./application.constant";
export * from "./localStorage.constant";
export * from "./store-constant";
...

@/constant导入的文件

import { localStorageItem  } from "@/constants";

export function makeFormDataObject() {
  return {
    companyId: parseInt(localStorage.getItem(localStorageItem.COMPANY_ID)),   
  };
}

在该函数中,未定义makeFormDataObject localStorageItem
如何解决此问题?

ve7v8dk2

ve7v8dk21#

Webpack是我们用来把所有东西捆绑在一起的工具。即使是这种语法export * from "./design.constant";也是超级用户友好的,有时候它不起作用。当它不起作用时,对于有导入问题的文件,你需要手动导入和导出函数/对象。第一次导出必须是有问题实体的文件。其他的可以保持不变。
示例:

import { 
 localStorageItem
} from "./localStorage.constant";

export {
  localStorageItem
};

export * from "./design.constant";
export * from "./application.constant";
export * from "./store-constant";

相关问题