写法1
// profile.js 导出模块
export var firstName = 'Michael';
export var lastName = 'Jackson';
export var year = 1958;
//useage.js 导入模块
import {firstName, lastName, year} from './profile';
console.log(firstName)
写法2
// profile.js 导出模块
var firstName = 'Michael';
var lastName = 'Jackson';
var year = 1958;
export {firstName, lastName, year};
//useage.js 导入模块
import {firstName, lastName, year} from './profile';
console.log(firstName)
写法3
//helper.js 导出模块
export function getName(){}
export function getYear(){}
//main.js 导入模块
import {getName, getYear} from './helper';
getName()
写法4
//helper.js 导出模块
function getName(){}
function getYear(){}
export {getName, getYear}
//main.js 导入模块
import {getName, getYear} from './helper';
getName()
写法5
// export-default.js
export default function () {
console.log('foo');
}
// import-default.js
import getName from './export-default'
getName()
网友评论