使用jq(版本不同导入方式也不同)
<script src="js/jquery-1.11.3.min.js"></script>
<script>
if (typeof module === 'object') {
window.jQuery = window.$ = module.exports;
};
</script>
页面跳转
window.location.href = 'home.html'
使用node模块
在main.js中配置
// 隐藏菜单栏
Menu.setApplicationMenu(null)
mainWindow = new BrowserWindow({
// 如果不默认全屏就开启这个
width: 1024,
height: 682,
webPreferences: {
//注意大小写
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true, // 使用remote模块
webSecurity: false,
preload: path.join(__dirname, 'preload.js')
}
})
// 默认打开工具栏
mainWindow.webContents.openDevTools();
发送Ajax请求本地json数据
1.先在dist目录下新建data目录,下面新建json数据
2.请求
$(".btn_json").click(function(){
$.ajax({
type:"GET",
url:"data/json/index.json",
success:(res)=>{
console.log(res)
}
})
})
读取文件(node模块之读取文件)
1.在dist下新建data>video
2.获取
var path = require("path");
var fs = require("fs");
console.log(__dirname) // ...Main-win32-x64\resources\app\dist
fs.readdir(__dirname+"/data/video", function(err, files){
if(err){
return console.log(err)
}
console.log(files)
});
调用electron主进程方法
1.直接在dist下js文件中导入
const { app } = require('electron').remote
2.使用
// 退出
$("#exit").click(() => {
app.exit()
})
注意事项
1.不能使用 electron-store
2. 创建目录不能有中文