Electron使用中遇到的問題


1.引入jquery和bootstrap的時候報錯 Uncaught Error: Bootstrap's JavaScript requires jQuery  或者 Uncaught ReferenceError: $ is not defined

解決方案:底層是因為node和jquery沖突了。這里只說解決方法,在index.html中引入jquery和bootstrap前先引入下列代碼

    <script>
      window.nodeRequire = require;
      delete window.require;
      delete window.exports;
      delete window.module;
    </script>

最終結果代碼如下,就可以正常運行操作jquery等了

<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <h1 id="hh">這樣就可以啦</h1>
    <!-- All of the Node.js APIs are available in this renderer process. -->
    We are using Node.js <script>document.write(process.versions.node)</script>,
    Chromium <script>document.write(process.versions.chrome)</script>,
    and Electron <script>document.write(process.versions.electron)</script>.
    <script>
      window.nodeRequire = require;
      delete window.require;
      delete window.exports;
      delete window.module;
    </script>
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="./renderer.js">
       console.log($('#hh').text());
    </script>
  </body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM