我正在通过电子运行一个快速应用程序。
下面是main.js
const electron = require("electron"),
app = electron.app,
BrowserWindow = electron.BrowserWindow;
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
frame: false,
kiosk: true
});
mainWindow.loadURL(`file://${__dirname}/index.html`)
mainWindow.webContents.openDevTools();
mainWindow.on("closed", function () {
mainWindow = null;
})
}
app.on("ready", createWindow);
app.on("browser-window-created",function(e,window) {
window.setMenu(null);
});
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", function () {
if (mainWindow === null) {
createWindow();
}
});
下面是视图中的一个按钮,单击后我希望它关闭应用程序
<button id="close-btn"><i class="fa fa-cube" aria-hidden="true"></i> Close application</button>
本质上我想在单击按钮后激活这部分代码
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
您可以使用
const remote = require('electron').remote
let w = remote.getCurrentWindow()
w.close()
关闭您的应用程序。
如果你使用的是 jQuery
const remote = require('electron').remote
$('#close-btn').on('click', e => {
remote.getCurrentWindow().close()
})
如果你使用的是 Vue.js
<template>
<button @click="close"><i class="fa fa-cube" aria-hidden="true"></i> Close application</button>
</template>
<script>
const remote = require('electron').remote
export default{
data(){
return {
w: remote.getCurrentWindow(),
}
},
methods: {
close() {
this.w.close()
}
}
}
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)