node中导入模块:var 名称 = require('模块标识符')node
node中向外暴露成员的形式:module.exports = {}bash
在ES6中,也经过规范的形式,规定了ES6中如何导入和导出模块ui
ES6中导入模块,使用 import 模块名称 from '模块标识符' import '表示路径'spa
import *** from *** 是ES6中导入模块的方式code
注意:string
一、export default 向外暴露的成员,能够使用任意变量来接收it
二、在一个模块中,export default 只容许向外暴露一次console
三、在一个模块中,能够同时使用export default 和export 向外暴露成员class
四、使用export向外暴露的成员,只能使用{ }的形式来接收,这种形式,叫作【按需导出】test
五、export能够向外暴露多个成员,同时,若是某些成员,在import导入时,不须要,能够不在{ }中定义
六、使用export导出的成员,必须严格按照导出时候的名称,来使用{ }按需接收
七、使用export导出的成员,若是想换个变量名称接收,能够使用as来起别名
var info = {
name: 'zs',
age: 20
}
export default info
import person from './test.js'
console.log(person);
var info = {
name: 'zs',
age: 20
}
export default info
export var title = '小星星'
export var content = '哈哈哈'
import person, {title, content as content1} from './test.js'
console.log(person);
console.log(title + '=======' + content1);
复制代码