当前位置: 首页 > news >正文

咸宁制作网站万网域名注册

咸宁制作网站,万网域名注册,洪梅做网站,用wordpress好还是文章目录 渲染进程到主进程(单向)渲染进程到主进程(双向)主进程到渲染进程 (单向,可模拟双向) 渲染进程到主进程(单向) send (render 发送)on &a…

文章目录

  • 渲染进程到主进程(单向)
  • 渲染进程到主进程(双向)
  • 主进程到渲染进程 (单向,可模拟双向)

渲染进程到主进程(单向)

send (render 发送)on (main 监听)

// main.js 主要代码// electron/main includes types for all main process modules.
const { app, ipcMain } =  require("electron/main")
app.whenReady().then(()=>{// 需要在 HTML 文件加载之前监听,保证从渲染器调用之前处理程序能够准备就绪。ipcMain.on('set-title', (event, title) => {const webContents = event.senderconst win = BrowserWindow.fromWebContents(webContents)win.setTitle(title)})createWindow(); // 创建窗口
})
// preload.js // electron/renderer includes types for all renderer process modules.
const { contextBridge, ipcRenderer } = require("electron/renderer")
contextBridge.exposeInMainWorld("electronAPI", ()=>{setTitle: (title) => ipcRenderer.send('set-title',title)
})
// renderer.js// 插入html中的js, 运行于渲染程序中
const setButton = document.getElementById('btn')
const titleInput = document.getElementById('title')
setButton.addEventListener('click', () => {const title = titleInput.valuewindow.electronAPI.setTitle(title)
})

渲染进程到主进程(双向)

invoke(render 发送)handle(main 监听)

const { app, ipcMain, dialog } =  require("electron/main")
app.whenReady().then(()=>{// 需要在 HTML 文件加载之前监听,保证从渲染器调用之前处理程序能够准备就绪。// IPC 通道名称上的 dialog: 前缀对代码没有影响。 它仅用作命名空间以帮助提高代码的可读性。ipcMain.handle('dialog:openFile', async () => {const { canceled, filePaths } = await dialog.showOpenDialog()if(!canceled) return filePaths[0]})createWindow(); // 创建窗口
})
// preload.js // electron/renderer includes types for all renderer process modules.
const { contextBridge, ipcRenderer } = require("electron/renderer")
contextBridge.exposeInMainWorld("electronAPI", ()=>{openFile: () => ipcRenderer.invoke('dialog:openFile')
})
// renderer.js// 插入html中的js, 运行于渲染程序中
const setButton = document.getElementById('btn')
const filePath= document.getElementById('filePath')
setButton.addEventListener('click', async () => {const path= await window.electronAPI.openFile()filePath.innerText= path
})

主进程到渲染进程 (单向,可模拟双向)

send on

// main.jsconst { app, BrowserWindow, Menu, ipcMain } = require('electron/main')
const path = require('node:path')function createWindow () {const mainWindow = new BrowserWindow({webPreferences: {preload: path.join(__dirname, 'preload.js')}})const menu = Menu.buildFromTemplate([{label: app.name,submenu: [{// 使用 webContents.send API 将 IPC 消息从主进程发送到目标渲染器。// 其使用方式与 ipcRenderer.send 相同。click: () => mainWindow.webContents.send('update-counter', 1),label: 'Increment'},{click: () => mainWindow.webContents.send('update-counter', -1),label: 'Decrement'}]}])Menu.setApplicationMenu(menu)mainWindow.loadFile('index.html')
}app.whenReady().then(() => {// 模拟双向通信,接收渲染进程发送的数据,"update-counter" 触发ipcMain.on('counter-value', (_event, value) => {console.log(value) })createWindow()
})
// preload.jsconst { contextBridge, ipcRenderer } = require("electron/renderer")
contextBridge.exposeInMainWorld("electronAPI", {onUpdateCounter: (callback) => ipcRenderer.on("update-counter", (event,value) => callback(value)),sendCount: (value) => ipcRender.send('counter-value', value)
})
// render.js
const count = document.getElementById("count")
window.electronAPI.onUpdateCounter((value)=>{const newValue = Number(count.innerText) + value;count.innerText = newValue.toString();window.electronAPI.sendCount(newValue)
})
http://www.hkea.cn/news/320968/

相关文章:

  • 长沙网站seo公司百度权重5的网站能卖多少钱
  • 常德网站开发百度推广登录首页网址
  • 网站建设软件设计推广官网
  • 网站运营阶段站长之家app
  • discuz网站标题百度广告推广价格
  • 广州学校论坛网站建设疫情排行榜最新消息
  • 古董手表网站网络营销的主要方式和技巧
  • 做公司网站要那些资料百度电脑版下载官方
  • 定州网站建设公司企业网站源码
  • 0基础1小时网站建设教程如何给自己的公司建网站
  • 成都网站建设s1emens电商平台怎么加入
  • 六合哪家做网站建设域名注册查询软件
  • 网站建设的方案费用2023年新冠疫情最新消息
  • 九星市场做网站快速将网站seo
  • 长春做网站推广的公司提升神马关键词排名报价
  • 金融网站cms百度网盘客服电话人工服务
  • 美观网站建设物美价廉seo网站优化专员
  • 网站设计应该怎么做推广软文代写
  • 网站建设工作室发展百度收录教程
  • 没有网站 可以做百度口碑吗成都网站制作
  • 医院系统网站建设百度宁波营销中心
  • 网站劫持代码杭州互联网公司排名榜
  • 做网站找哪个部门吸引人的推广标题
  • 网站制作软件名字线做竞价推广代运营公司
  • avada如何做中英文网站沈阳百度推广排名优化
  • 做网站品长沙网络营销公司排名
  • b2b商贸网站环球网最新消息疫情
  • wordpress next主题什么是seo教程
  • 如何规划一个网站快手秒赞秒评网站推广
  • 中国网站开发网站seo需要用到哪些工具