[英]Getting type error importing jQuery using ES6 syntax
Following the answer to this question I tried to import jQuery using import {$, jQuery} from 'jquery';
在回答这个问题之后,我尝试使用import {$, jQuery} from 'jquery';
来导入jQuery import {$, jQuery} from 'jquery';
. 。 and am getting the error Uncaught TypeError: (0 , _jquery.$) is not a function
in the browser. 并且收到错误Uncaught TypeError: (0 , _jquery.$) is not a function
在浏览器中Uncaught TypeError: (0 , _jquery.$) is not a function
。 Am using Babel with the ES2015 preset to transpile my Code. 我正在将Babel与ES2015预设一起使用来移植我的代码。 If I use two separate imports ie import $ from 'jquery'; import jQuery from 'jquery'
如果我使用两个单独的导入,即import $ from 'jquery'; import jQuery from 'jquery'
import $ from 'jquery'; import jQuery from 'jquery'
then it works fine. import $ from 'jquery'; import jQuery from 'jquery'
然后它可以正常工作。 Why can't I use the combined syntax? 为什么不能使用组合语法?
Because import $ from 'jQuery'
is short for import {default as $} from 'jQuery'
. 因为import $ from 'jQuery'
import {default as $} from 'jQuery'
缩写。 If you import {$, jQuery}
, those are two names that are not exported. 如果导入{$, jQuery}
,则这两个名称不会导出。 You can however use 但是,您可以使用
import {
default as $,
default as jQuery
} from 'jQuery';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.