Using BrowserWindow.on ('close') in electron cannot prevent window closing

I loaded this listener in the created hook of the vue component:

($electron points to require ("electron"), which is a function of the vue-electron package)

created () {
    this.$electron.remote.getCurrentWindow.on("close", (e) => {
        e.preventDefault()
    }
}

according to the official document, e.preventDefault () will prevent the window from closing, but the window is still closed.

did not find the reason, what is the possible reason?

< hr >

the project is built with electron-vue template and runs in development mode

  • electron: 1.8.7
  • vue: 2.5.13
  • vue-router: 3.0.1

binds via remote, which is actually on the main process. Due to asynchronism, shutdown cannot be prevented during the rendering process. Block

with onbeforeload in the rendering process
Menu