如下:
<script src="../assets/js/jquery-1.10.2.js"></script>
方法1
改为:
<script>window.$ = window.jQuery = require("../assets/js/jquery-1.10.2.js")</script>
即可。
方法2:
或者在
win = new BrowserWindow({ webPreferences:{ nodeIntegration:false, } })
注意这样就不能在页面中使用nodejs和Electron APIs了。
方法3:
<script> window.nodeRequire = require; delete window.require; delete window.exports; delete window.module; </script> <script src="../assets/js/jquery-1.10.2.js"></script>
原因:
其实就是Electron中存在如下代码:
if ( typeof module === "object" && typeof module.exports === "object" ) { // set jQuery in `module` } else { // set jQuery in `window` }
参考1:https://electron.atom.io/docs/faq/#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron
参考2:https://github.com/electron/electron/issues/254
时间: 2024-10-03 22:40:35