Javascript/Typescript-导入类的不同语法
在angular中导入的两种语法有什么不同:Javascript/Typescript-导入类的不同语法,javascript,typescript,lodash,Javascript,Typescript,Lodash,在angular中导入的两种语法有什么不同: import partition from 'lodash/fp/partition'; import { partition } from 'lodash/fp/partition'; 第一个有效,但另一个对我无效 感谢第一个程序从模块“lodash/fp/partition”导入默认导出,而第二个程序尝试对模块的导出进行分解,只获取分区导出 对于本模块: module.exports={ 默认值:1, 分区:2, } 从“lodash/fp/
import partition from 'lodash/fp/partition';
import { partition } from 'lodash/fp/partition';
第一个有效,但另一个对我无效
感谢第一个程序从模块“lodash/fp/partition”导入默认导出,而第二个程序尝试对模块的导出进行分解,只获取
分区
导出
对于本模块:
module.exports={
默认值:1,
分区:2,
}
从“lodash/fp/partition”导入分区;将是:
partion==1
从'lodash/fp/partition'导入{partition};将是:
partion==2
对于本模块:
module.exports=1
从“lodash/fp/partition”导入分区;将是:
partion==1
从'lodash/fp/partition'导入{partition};将是:
partion===未定义
第一个用于导入标记为默认值的内容
:
// lodash/fp/partiotion
export const a = 5;
export const b = 'b';
export default {key: 'value'}; // only this line will be imported using the first syntax
第二个选项允许您指定要导入的内容:
// lodash/fp/partiotion
export const a = 5;
export const b = 7;
export const partition = () => {}; // you are directly importing only this line
请澄清,这不是角度特性。这是一个
javascript ES6
功能。有关如何使用导入检查MDN文档的更多详细信息,请参阅。