您现在的位置:首页 >> 前端 >> 内容

ES6模块化操作实例教程

时间:2018/2/6 14:31:01 点击:

  核心提示:案例1:temp.jsvar a = js;var b = 脚本;var c = web;export {a,b,c}export function add(a,b){return a + b;}//...

案例1:

temp.js

var a = 'js';
var b = '脚本';
var c = 'web';

export {
    a,b,c
}

export function add(a,b){
    return a + b;
}

// export {
//     // 起个语义化名字
//     name as a,
//     // cname as b,
//     // skill as c  
// }

index.js

// export   输出操作
// import   引入操作
import {a,b,c} from './temp';

console.log(`a = ${a}`);
console.log(`b = ${b}`);
console.log(`c = ${c}`);

ES6模块化操作实例教程

案例2:

temp.js

export default var c = 'js';

index.js

import shy from './temp';
console.log(`shy = ${shy}`);

Tags:ES S6 6模 模块 
作者:网络 来源:zjsfdx的博客