es6中export和import用法

1. export 对外开放功能

//文件名 exportEx.js   导出变量,方法,类
export let a = 1;
let b = 2;
export {
    b
};
let c = 3;
let d = 4;
export {
    c,
    d
};

//导出方法
function f1() {
    console.log("f1");
}
export {
    f1 
};
export function f2() {
    console.log("f2");
}

function f3() {
    console.log("f3");
}

function f4() {
    console.log("f3");
}

export {
    f3,
    f4
};

2.import引用功能

import {f2} from "./exportEx.js"

function test() {
    f2();
    console.log("test")
}

3.ES6的import和export如何在html中使用?

     需要使用webpack打包后在html中引用对应JS文件。

猜你喜欢

转载自www.cnblogs.com/wasoft/p/12557760.html