将jQuery集成到电子应用程序中
我正在尝试将jquery功能添加到以电子方式编写的桌面应用程序中
使用电子快速启动仓库,我将下载的jquery文件添加到main.html
文件中,如下所示:
I'm trying to add jquery functionality to a desktop app written in electron
Using the electron-quick-start repo i'm adding the downloaded jquery file to the main.html
file like so:
<script> require("./jquery.min.js"); </script>
等等:
<script>window.$ = window.jQuery = require('./jquery.min.js');</script>
然后在index.js
文件中,我在createWindow
函数中添加代码,因为这似乎是正确的位置,但是老实说,我尝试在任何地方都会或多或少地得到相同的错误.
Then in the index.js
file i'm adding code in the createWindow
function, since that seems the proper place, but to be honest any place i try gets me the same error more or less.
mainWindow.$
是undefined
,BrowserWindow
和app
mainWindow
在createWindow
函数内部定义,如下所示:
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow
is defined inside the createWindow
function like so:
mainWindow = new BrowserWindow({width: 800, height: 600})
,并在文件顶部声明BrowserWindow,如下所示:
const BrowserWindow = electron.BrowserWindow
and BrowserWindow is declared on top of the file like so:
const BrowserWindow = electron.BrowserWindow
知道我要去哪里哪里了,应该更改/添加哪些声明?
Any idea where i'm going wrong, what declarations i should change/add?
预先感谢
使用电子时,还会在DOM中插入一些其他符号,从而引起问题.因此,您可以按照以下方式使用jquery
While using electron, some additional symbols are also inserted into DOM causing problems. So, you can use jquery as follow
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js" onload="window.$ = window.jQuery = module.exports;"></script>
请注意"onload"中的代码.
Notice the code inside "onload".