导出的根本用法
// 导出数据export let name = 'learn';export const age = 18;// 导出类export class Rect { constructor(width, height){ this.width = width; this.height = height; }}// 导出函数export function sum(a, b){ return a + b;}
导入的根本语法
import {name, age, Rect, sum} from './example.js';// 不能给导入的绑定赋值,如 name = 'zhangsan'; 会报错
导入整个模块
import * as example from './example.js'// example 就蕴含了js文件里的全副export内容
import export 不容许呈现在其余语句或函数内,如if里。、
改名的状况
import {sum as add} from './example.js'