electron 系統對象process

用於處理關於系統、系統進程的對象

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
    },
  })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章