fansleep 2021-06-04 13:26 采纳率: 0%
浏览 231
已结题

console报错:Cannot read property 'getCurrentWindow

index.js

const { app, BrowserWindow } = require('electron')
function createWindow () {
       win = new BrowserWindow({
           webPreferences: {nodeIntegration: true, NodejsenableRemoteModule: true, contextIsolation: false},
       })
    win.on('ready-to-show',()=> {
        win.show()
    })


      win.loadFile('index.html')

      win.on('closed',()=>{
             console.log('closed')
             win = null
      })
} 
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

app.on('ready', createWindow)
app.on('window-all-closed',()=>{
       console.log('window-all-closed')
       if(process.platform !== 'darwin') {
          app.quit()
       }
})
app.on('activate',() =>{
       console.log('activate')
       if(win == null) {
             createWindow()
       }
})

 

index.html

<!DOCTYPE html>
<html>
  <head>
           <meta charset="UTF-8">
           <title>绿色</title>
            <script src="event.js"></script>
  </head>
   <body>
          <img src="H:/源图/led.jpg"/>
          <h2>书名:<i>《绿色的树叶》</i></h2>
          <br>
          <br>
          出版社:<u>人民日报</u>
          <br>
          <br>
          原价:<del>188</del>元  促销价:66元
          <br>
          <br>
      <button id="button" onclick="onClick()">进入锁定模式</button>
  </body>
</html>

event.js

const remote = require("electron").remote
function onClick() {
    const button = document.getElementById('button')
    const win = remote.getCurrentWindow()
    if(win.isKiosk()){
     win.setKiosk(false)
     button.innerText = "进入锁定模式"
    }
    else{
        win.setKiosk(true)
        button.innerText = "退出锁定模式"
    }
}

 console报错

 

刚开始学习electron,实在找不出问题在哪?希望路过的好心人帮忙一下 

  • 写回答

3条回答 默认 最新

  • 封印di恶魔 2021-06-04 15:07
    关注

    electron 10中,修改了enableRemoteModule默认为false,我们需要手动将其修改为true

    webPreferences配置参数enableRemoteModule:true来打开remote模块

    https://blog.csdn.net/liu19721018/article/details/108922594

    评论

报告相同问题?

悬赏问题

  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图
  • ¥15 智能除草机器人方案设计
  • ¥15 对接wps协作接口实现消息发送