64

通过使用require(./filename),我可以在文件名中包含和执行代码,而无需在文件本身中定义任何导出。

ES6 中的等价物是什么import

谢谢

4

1 回答 1

103

等价物很简单:

import "./filename";

以下是一些可能的语法变化:

import defaultMember from "module-name";  

import * as name from "module-name";  

import { member } from "module-name";  

import { member as alias } from "module-name";  

import { member1 , member2 } from "module-name";  

import { member1 , member2 as alias2 , [...] } from "module-name";  

import defaultMember, { member [ , [...] ] } from "module-name";  

import defaultMember, * as name from "module-name";  

import "module-name";

来源: MDN

于 2016-12-16T08:07:29.450 回答