1

export

// profile.js
export var firstName = 'David';
export var lastName = 'Belle';
export var year = 1973;

等价于
var firstName = 'David';
var lastName = 'Belle';
var year = 1973;
export {first, lastName, year}


import

import {firstName, lastName, year} from './profile';
import {someMethod, another as newName} from './expoter';

export default 语句

如果不想为某个属性或方法指定输入的名称,可以使用export default 语句。

export default function foo() {
    console.log('foo');
}

export default 42;


export {area as circleArea} from 'circle';

小渝人儿
1.1k 声望850 粉丝

前端工程师