主进程很少有需求需要弹出菜单,所以以下代码怕是没有用
//主进程很少有需求需要弹出菜单
const {Menu} = require('electron')
setTimeout(()=>{
//如何在主进程中弹出菜单
let template = [
{label:'第一个菜单项目'},
{label:'第二个菜单项目'},
{role:'copy'},
{type:'separator'},
{label:'第三个菜单项目'},
{label:'第四个菜单项目'},
]
let menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
menu.popup()
},2000)
渲染进程弹出菜单
let { Menu, MenuItem } = remote
document.getElementById('popMenu').onclick = function () {
let template = [
{ label: "第一个菜单" },
{
label: '点击测试', click: () => {
console.log('点击事件ok')
}
},
{ role: 'undo' },
{ label: "旅游", type: 'checkbox', checked: true },
{ label: "吃", type: 'checkbox', checked: true },
{ label: "逛街", type: 'checkbox', checked: false },
]
let menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
menu.popup()
}