export:
在一个模块文件里可以有多个export用于暴露模块的接口,但只能有一个export default用于暴露模块的默认接口,例如:
export const myStr = 'hello world'
export const myNum = 1000
export const myBoole = false
export default {
id: 1,
title: 'this is title',
}
复制代码
import:
引入模块的时候通过export暴露的接口需要用{}包起来,通过export暴露的接口则不用,例如:
// 引入默认输出对象
import defaultObj from './test.js'
// 引入多个输出变量
import {myStr, myNum, myBoole} from './test.js'
// 同时引入默认输出对象和多个输出变量
import defaultObj {myStr, myNum, myBoole} from './test.js'
复制代码
其实ES6的模块化还有其他一些方式,等有空再补上吧。