2017-08-15 20 views
0

我想在我的React應用程序中使用這個庫:http://propeller.in,但它建立在jQuery上。我已經加入我的Index.js以下相關的代碼陣營組成:如何在React.js中使用jQuery依賴節點模塊?

import $ from 'jquery'; 
import 'propellerkit/dist/js/propeller.js'; 

我也試過這樣:

import 'jquery/dist/js/jquery.js'; 
import 'propellerkit/dist/js/propeller.js'; 

我確信這兩個節點模塊安裝。出於某種原因,我不斷收到$ is not defined錯誤。

+0

你可以試試'進口*爲$從 'jQuery的';'但因爲我沒有不,我沒有發現它值得頂級答案。 – Brian

+0

謝謝,但同樣的錯誤。 –

+0

您是否嘗試'從'jquery/dist/js/jquery.js'導入*作爲$;''或者'只導入'jquery';'?這應該將jQuery暴露爲dist webpack創建的「全局」。 – Brian

回答

1

如果您使用的WebPack捆綁,可以jquery使用ProvidePlugin提供,

new webpack.ProvidePlugin({ 
    $: 'jquery', 
    jQuery: 'jquery' // this will try to find node jquery module 
}) 

鏈接到docs

+0

完美。謝謝! –

相關問題