export default 與 export 的用法

export 相對於提供一個接口給外界,在其他文件中通過import來引用。在一個模塊中,export default 只允許向外暴露一次。

例如:
// test.js
var person = {
    name: 'ttt',
    age: 35
}

export default person

export var name = 'ttt'
 
export var age = 30

test.js使用export default 和 export 向外暴露的成員

import person, {name, age as myAge} from './test.js'

console.log(person);
console.log(name + ',' + myAge);

 

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