ES6-模块

2020-03-13  本文已影响0人  zhenghongmo

title:
date: 2019-01-11 11:35:56
tags:


import

导入整个模块的内容

import * as name from './1.js'

导入单个导出

import {myExport} from './1.js'

导入多个导出

import {foo, bar} from './1.js'

重命名导出

import { reallyReallyLongModuleMemberName as shortName, anotherLongModuleName as short } from './1.js'

导入默认值

import myDefault from './1.js'

仅为副作用而导入一个模块

import './1.js'

export

//1.js
function cube(x) {
  return x * x * x;
}

const foo = Math.PI + Math.SQRT2;

export { cube,foo };

//main.js

import { cube, foo } from './1.js';
console.log(cube(3)); // 27
console.log(foo);    // 4.555806215962888

export default

//1.js
export default function cube(x) {
  return x * x * x;
}

//main.js
import fn from './1.js'
fn(3) //27
上一篇下一篇

猜你喜欢

热点阅读