如何在Javascript中为默认导入添加别名? [英] How can I alias a default import in Javascript?

查看:1258
本文介绍了如何在Javascript中为默认导入添加别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ES6模块,我知道可以为命名的import别名

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?

推荐答案

defaultMember已经的别名-不需要是导出函数/事物的名称.随便

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';

或者,你可以做

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

但这太深奥了.

这篇关于如何在Javascript中为默认导入添加别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆