代码之家  ›  专栏  ›  技术社区  ›  cdarwin

“$.getJSON不是一个函数”,使用来自babel节点和ES6的jQuery[duplicate]

  •  0
  • cdarwin  · 技术社区  · 7 年前

    我正在尝试使用ES6导入jQuery,最重要的是, 我正在使用babel节点(cli)运行代码。

    我读过 a question

    npm i --save jquery
    

    然后

    import {$,jQuery} from 'jquery';
    
    console.log($);
    

    undefined 登录到控制台,无法使用jQuery。

    如何导入 $ ?

    import $ from 'jquery';
    

    根据@Jai的建议和 npm manual console.log($) , $.getJSON("www.google.com") 还给我 TypeError: _jquery2.default.getJSON is not a function .

    1 回复  |  直到 7 年前
        1
  •  2
  •   Xixis    7 年前

    我建议你尝试使用下面的代码

    import $ from 'jquery';

    import jQuery from 'jquery';