export 与 export default区别
export 与 export default区别
1、export
export 可以直接导出或者先定义后导出。
// eg: 直接导出
export const a = '1234'
export const b = () => { }
//eg: 先定义后导出
const a = '1234'
const b = () => { }
export { a, b}
2、export default
export default 只能直接输出,是模块对外接口,只有一个,所以只能出现一次。
export default function(){ }
export default实际上输出一个名为default的变量和方法,在引入的时候也可以随意命名此变量和方法
通过两者的导出的区别,两者的引入也有区别:
export 导出的对象,导入写法:
import { a, b} from ‘module’
export default 导出对象的写法:
import module from ‘module’
还没有评论,来说两句吧...