用於處理關於系統、系統進程的對象
1、給頁面添加事件是渲染進程,main.js是主進程,所以事件方法需要在渲染進程,也就是main.js中寫
2、谷歌chrome綁定事件不能直接在標籤上綁定,需要js動態綁定
3、在main.js中->new BrowserWindow->webPreferences內添加
nodeIntegration:true
4、ctrl r 刷新頁面
代碼示例:
render.js:
var btn=document.querySelector('button');
btn.onclick=gets;
function gets()
{
console.log(process.getCPUUsage());
//環境變量
console.log(process.env);
//cpu操作位數
console.log(process.arch);
}
main.js:
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration:true
},
})