electron?dialog.showMessageBox的使用案例
更新時間:2023年08月10日 10:08:46 作者:xjhqre
Electron?Dialog?模塊提供了api來展示原生的系統(tǒng)對話框,本文主要介紹了electron?dialog.showMessageBox的使用案例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
electron 版本:25.3.1
index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello World!</title> <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';"/> </head> <body> <h1>Hello World!</h1> <button id="sad">點我彈出消息對話框</button> <script> const {ipcRenderer} = require('electron') document.querySelector('#sad').addEventListener('click', () => { ipcRenderer.send('open-message-dialog') }) </script> </body> </html>
main.js
const {app, BrowserWindow, ipcMain, dialog} = require('electron') function createWindow() { ? ? let win = new BrowserWindow({ ? ? ? ? width: 800, ? ? ? ? height: 600, ? ? ? ? webPreferences: { ? ? ? ? ? ? nodeIntegration: true, ? ? ? ? ? ? contextIsolation: false ? ? ? ? } ? ? }) ? ? win.loadFile('index.html') ? ? ipcMain.on('open-message-dialog', () => { ? ? ? ? dialog.showMessageBox({ ? ? ? ? ? ? title: '消息', ? ? ? ? ? ? message: '這是一個消息框。', ? ? ? ? ? ? type: 'info', ? ? ? ? ? ? buttons: ['確定', '取消'] ? ? ? ? }) ? ? }) } app.whenReady().then(createWindow) app.on('window-all-closed', function () { ? ? if (process.platform !== 'darwin') app.quit() }) app.on('activate', () => { ? ? if (BrowserWindow.getAllWindows().length === 0) { ? ? ? ? createWindow() ? ? } })
效果展示
到此這篇關(guān)于electron dialog.showMessageBox的使用案例的文章就介紹到這了,更多相關(guān)electron dialog.showMessageBox內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
相關(guān)文章
vue 自定義提示框(Toast)組件的實現(xiàn)代碼
這篇文章主要介紹了vue 自定義提示框(Toast)組件的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08Element-ui中元素滾動時el-option超出元素區(qū)域的問題
這篇文章主要介紹了Element-ui中元素滾動時el-option超出元素區(qū)域的問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05Vue3中如何使用v-model高級用法參數(shù)綁定傳值
本文給大家介紹Vue3中使用v-model高級用法參數(shù)綁定傳值的相關(guān)知識,包括單個輸入框傳值和多個輸入框傳值,一個組件接受多個v-model值,本文通過實例代碼給大家介紹的非常詳細,需要的朋友參考下吧2023-10-10