暴露语法
export 代码块
export const a = “a”;
export function test(){};
export {代码块的标识}
const a = "a";
function test(){};
export {a,test}
export default 对象 (这种暴露形式只能使用一次;当然三种暴露形式是可以混合使用的)
const a = "a";
function test(){};
export default{a:a,test:test}
引入语法
import {代码块的标识…,default as obj} from url
(可以拿到所有暴露形式暴露出来的内容)
(缺点:要记住所有的代码块的标识)
import * as obj from url
(可以拿到所有暴露形式暴露出来的内容;这些内容都挂靠到obj对象上作为了属性)
(不用记住所有的标识)
import obj from url
(只有拿到default暴露出来的内容;obj就是default对应的对象)
简便写法(结合了import&export):
export {default as obj} from url