ES6 - Convert from 'require' to 'impor

2019-01-04 13:03发布

If the alternative to:

 var Foo = require('foo');

is:

 import Foo from 'foo';

What is the alternative to:

var Bar = require('foo').batz

Could it be:

import {batz}  from 'foo' ?

1条回答
我只想做你的唯一
2楼-- · 2019-01-04 13:25

Nearly. It does however depend on how you are exporting them.

  • named exports (export var batz = …):

    import {batz as Bar} from 'foo';
    
  • default-exported object (export default {batz: …};) - should not be used:

    import Foo from 'foo';
    var Bar = Foo.batz;
    
查看更多
登录 后发表回答