导入模块
通过 import 关键字
// 只导入一个
import {sum} from "./example.js"
// 导入多个
import {sum,multiply,time} from "./exportExample.js"
// 导入一整个模块
import * as example from "./exportExample.js"
导出模块
导出通过 export 关键字
// 可以将 export 放在任何变量,函数或类声明的前面
export var firstName = 'Chen';
export var lastName = 'Sunny';
export var year = 1998;
// 也可以使用大括号指定所要输出的一组变量
var firstName = 'Chen';
var lastName = 'Sunny';
var year = 1998; export {firstName, lastName, year};
// 使用 export default 时,对应的 import 语句不需要使用大括号
let bosh = function crs(){}
export default bosh;
import crc from 'crc';
// 不使用 export default 时,对应的 import 语句需要使用大括号
let bosh = function crs(){}
export bosh;
import {crc} from 'crc';