【问题标题】:Unable to add JQuery Mobile in ReactJS - Can't resolve 'jquery-mobile'无法在 ReactJS 中添加 JQuery Mobile - 无法解析“jquery-mobile”
【发布时间】:2017-08-22 09:30:29
【问题描述】:

我正在尝试在我的 ReactJS 应用程序中添加 JQM。我正在做的添加它是:

npm install jquery@1.11.1 --save-dev
npm install jquery-mobile --save-dev

它将JQueryJQM 添加到模块,但问题是当我在我的应用程序中使用它时:

import $ from 'jquery';
import 'jquery-mobile';

它在控制台中给我以下错误:

找不到模块:错误:无法解析“/var/www/html/react/phonegapApp/”中的“jquery-mobile”

此外,当我使用 import JQuery 时,它的版本会自动从 ^1.11.1 更新到 package.json 文件中的最新版本 ^3.2.1 作为 JQM NPM 模块所需的版本应该小于1.11.1

【问题讨论】:

    标签: jquery reactjs jquery-mobile npm phonegap


    【解决方案1】:

    您必须导入 jquery,然后像这样在 componentDidMount 中使用您的代码:

    import $ from 'jquery';
    
    class App extends Component {
      componentDidMount = () => {
          // Your Jquery code here for ex:
          $('.message a').click(function(){
          $('form').animate({height: "toggle", opacity: "toggle"}, "slow");
          });
      }

    【讨论】:

      猜你喜欢
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多