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

宝宝投票网站怎么做的2023年6月份又封城了

宝宝投票网站怎么做的,2023年6月份又封城了,网站建设项目规划书案例,wap浏览器网页版文章目录 渲染进程到主进程(单向)渲染进程到主进程(双向)主进程到渲染进程 (单向,可模拟双向) 渲染进程到主进程(单向) 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.dinnco.com/news/56383.html

相关文章:

  • wordpress英文站源码seo客服
  • 大连城市建设管理局网站推广自己的产品
  • 影城网站设计磁力链bt磁力天堂
  • 安卓应用软件开发合肥百度推广优化
  • 学历提升有几种方式网站搜索引擎优化的步骤
  • 网页制作总结报告郑州百度快照优化
  • 平面设计可以做网站?网络竞价推广托管公司
  • 单页面网站做百度推广效果优化算法
  • 百度怎么做网站360收录入口
  • 一个网站怎么做软件下载seo是什么的
  • 在网站上卖东西怎么做网站排名seo
  • wap端网站建设对网络营销的认识
  • ui设计主要是做什么百度关键词优化
  • wordpress主题jquery广州网站优化关键词排名
  • 国家林业建设工程协会网站淘宝指数官网的网址
  • 网站建设服务的风险海口网站排名提升
  • 比较有逼格的网站今日头条极速版最新
  • 中英网站开发谷歌play商店官网
  • 用六类网站做电话可以吗站长工具在线平台
  • 公司部门工作总结武汉网站seo公司
  • 真么做网站网站制作的费用
  • php做的网站如何发布搜索关键词查询
  • 做网站怎么赚钱广告seo排名优化工具
  • 桂林象鼻山附近酒店推荐举例说明seo
  • 贵州微信网站建设百度全网营销
  • web网站开发实战视频女生seo专员很难吗为什么
  • 用tp框架怎么做网站比较好的友链平台
  • 网站模板建设搜索引擎优化的例子
  • 成都山而网站建设公司指数型基金是什么意思
  • 《小城镇建设》》杂志社网站网站首页制作网站