How can I alias a default import in Javascript?

十年热恋 提交于 2019-11-26 23:57:10

问题


Using ES6 modules, I know I can alias a named import

import { foo as bar } from 'my-module';

And I know I can import a default import

import defaultMember from 'my-module';

I'd like to alias a default import and I had thought the following would work

import defaultMember as alias from 'my-module';

but that results in a parsing (syntax) error.

How can I (or can I?) alias a default import?


回答1:


defaultMember already is an alias - it doesn't need to be the name of the exported function/thing. Just do

import alias from 'my-module';

Alternatively you can do

import {default as alias} from 'my-module';

but that's rather esoteric.



来源:https://stackoverflow.com/questions/39282253/how-can-i-alias-a-default-import-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!