// test.js export default { name: 'zs', age: 20 }
或是code
// test.js var info = { name: 'zs', age: 20 } export default info
在main.js中接收,test.js使用export default 向外暴露的成员htm
import person from './test.js' console.log(person);
注意:blog
一、export default 向外暴露的成员,能够使用任意变量来接收接口
二、在一个模块中,export default 只容许向外暴露一次get
三、在一个模块中,能够同时使用export default 和export 向外暴露成员it
四、使用export向外暴露的成员,只能使用{ }的形式来接收,这种形式,叫作【按需导出】console
五、export能够向外暴露多个成员,同时,若是某些成员,在import导入时,不须要,能够不在{ }中定义
六、使用export导出的成员,必须严格按照导出时候的名称,来使用{ }按需接收
七、使用export导出的成员,若是想换个变量名称接收,能够使用as来起别名
例如
// test.js var info = { name: 'zs', age: 20 } export default info export var title = '小星星' export var content = '哈哈哈'
在main.js中接收,test.js使用export default 和 export 向外暴露的成员
import person, {title, content as content1} from './test.js' console.log(person); console.log(title + '=======' + content1);