You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// out.jsexportfunctionhi(){// ...}exportfunctionhello(){// ...}// export { hi as sayHi };// in.jsimport{hiassayHi,hello}from'out';sayHi();// 可以修改对象属性,但是不可以直接修改对象hello={};// errorhello.xx='xxx';// ok// 整体加载import*asoutfrom'out';out.hi();out.hello();// 注意不能对 out 以及 out 上 export 的属性进行修改out={};// errorout.hi=1;// errorout.hi.xxx='xxx';// ok
export default
它让你可以在 import 时无需关注实际的名字:
// out.jsexportdefaultfunction(){// 即使 function 有名字也无妨// ...}// in.jsimportanyNameYouLikefrom'out';// 也不需要用 {} 包裹名字
基本用法
export default
它让你可以在
import
时无需关注实际的名字:注意 :由于是编译阶段执行,所以在
import
中使用运行时语法是不错误的,比如使用import { 'hell' + 'o'} from 'out'
。CommonJs 和 ES6 模块区别
The text was updated successfully, but these errors were encountered: