Ember CLI and import ... as
Ember CLI and import ... as
在ember CLI中使用以下代码可以工作:
import X from 'source';
X.doSomething();
但是,使用另一种形式:
import {X as Y} from 'source';
Y.doSomething();
浏览器记录一个异常:
TypeError: Y is not defined
根据ES6规范,这应该是可行的。这种行为只是Ember CLI的限制,还是我的语法有问题?
我认为您的问题是使用了错误的导入语法。您拥有的第一个代码片段是导入默认导出,而第二个代码片段使用命名导出。看看下面的代码:
// This
import X from 'source';
// is to this
import Y from 'source';
// as this
import { X } from 'source';
// is to this
import { X as Y } from 'source';
在您的情况下,您应该使用第二个表单,因为您有一个默认导出。您也可以执行以下操作,但出于可读性的考虑,我建议您不要这样做。
import { default as Y } from 'source';
相关文章:
- 重写需要javascript中带有import关键字的语法
- 可以't连接客户端和服务器import.io
- jQuery .load with variable as url
- React.findDOMNode comes as undefined
- $scope is coming as undefined
- AltGr treated as Alt + Ctrl
- new Date('2011-12-15 00:00:00') is showing up as NaN
- CSS styling of <UL> as table
- Array.prototype.fill() different from fill as I go
- 为什么import关键字有用
- 在bookmarklet中使用@import和@font face(适用于Chrome,但不适用于Firefox)
- 在ES6的“import”语法中,如何准确地评估模块
- (!n%2) is the same as (!n%2 == 0)?
- Angulrjs:控制器不会通过带有“as”语句的工厂发送值
- 尝试理解$.inArray,或将$scope转换为“$scope”;控制器As”;AngularJS中的语法
- Mosync Javascript NativeUI Editbox as Password field
- TypeScript import/as vs import/require?
- Ember CLI and import ... as
- 检测到' import * as name '令牌
- 下面是什么意思:import register, * as fromRegister from './regis