es6(基礎二十) Module(模塊)

一、基本使用

// 導出
export let A = 123;
export function test() {
    console.log('test')
}

export class Hello{
    test(){
        console.log('hello test')
    }
}

// 導入模塊
import {A,test,Hello} from '/common/index'

二、全部導入

import * as lesson from '/common/index'

三、批量導出,不限制名字:採用export default

let A = 123;
let test = function test() {
    console.log('test')
}

class Hello{
    test(){
        console.log('hello test')
    }
}
export default {
    A,
    test,
    Hello
}

// 引入並使用

import demo16 from '/common/index'
console.log(demo16.A);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章