久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Electron 中操作 DOM

Manipulate DOM in Electron(在 Electron 中操作 DOM)
本文介紹了在 Electron 中操作 DOM的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在電子應用程序中操作 DOM 的最佳方式是什么?

What is the best way to manipulate DOM within an electron app?

我使用 ipc 和 webcontents 從文檔中制作了一些教程,但沒有成功

I made some tutorials from docs using ipc and webcontents with no luck

我的應用程序非常簡單,我只想像控制臺一樣使用網絡并顯示來自多個同步函數(主進程)結果的消息(渲染進程)

My app is so simple, I just want to use the web like a console and showing messages (render proc) comming from the results of several sync functions (main proc)

我用真實代碼更新了問題.

I updated the question with real code.

我要放另一個代碼,更容易看,更容易測試(我認為),是真實的代碼并且可以工作(但不像我想要的那樣)

I'm going to put another code, more simple to see and more simple to test (I think), is real code and works (but not like I want)

當我啟動電子時,只寫最后一條消息.好的,響應真的很快,我可能看不到第一條消息,但要丟棄我也放了一個 setTimeout 和一個大的 for() 循環(huán),以使大寫函數需要更長的時間

When I launch electron only writes the last message. Ok, the response is really fast and I may not see the first messsage but to discard that I put a setTimeout and a large for() loop too, to make the uppercase function takes longer

index.js

const electron = require('electron');
const {app} = electron;
const {BrowserWindow} = electron;
const ipc = require('electron').ipcMain

app.on('ready', () => {
  let win = new BrowserWindow({width: 800, height: 500});

  win.loadURL('file://' + __dirname + '/index.html');

  // Emitted when the window is closed.
  win.on('closed', () => {
    win = null;
  });

  // Event that return the arg in uppercase
  ipc.on('uppercase', function (event, arg) {
    event.returnValue = arg.toUpperCase()
  })
});

index.html

<html>
    <body>
      <div id="konsole">...</div>

      <script>
        const ipc = require('electron').ipcRenderer
        const konsole = document.getElementById('konsole')

        // Functions
        let reply, message

        // First MSG
        reply = ipc.sendSync('uppercase', 'Hi, I'm the first msg')
        message = `Uppercase message reply: ${reply}`
        document.getElementById('konsole').innerHTML = message

        // Second MSG
        reply = ipc.sendSync('uppercase', 'Hi, I'm the second msg')
        message = `Uppercase message reply: ${reply}`
        document.getElementById('konsole').innerHTML = message
      </script>
    </body>
</html>

推薦答案

您可以使用 webContents 和 IPC 在前端和后端之間進行通信.然后,您將能夠使用后端指令在前端操作您的代碼.

You can comminicate between your frond-end and back-end with webContents and IPC. Then, you'll be able to manipulate your codes in front-end with backend's directive.

例如(后端到前端);

您的 main.js 正在向您的前端發(fā)送消息.

Your main.js is sending a message to your front-end.

mainwindow.webContents.send('foo', 'do something for me');

您的前端將在這里歡迎該消息;

Your frond-end will welcome that message here;

const {ipcRenderer} = require('electron');

ipcRenderer.on('foo', (event, data) => {
        alert(data); // prints 'do something for me'
});

例如(前端到后端);

你的前端;

const {ipcRenderer} = require('electron');

ipcRenderer.send('bar',"I did something for you");

您的后端;

const {ipcMain} = require('electron');

ipcMain.on('bar', (event, arg) => {
  console.log(arg)  // prints "I did something for you"
  event.sender.send('foo', 'done') // You can also send a message like that
})

更新問題后更新;

我在本地嘗試了你的代碼,它似乎工作正常.

I tried your codes on my local, It seems like working.

您能否嘗試使用 insertAdjacentHTML 而不是 'innerHTML' 來確保或僅使用 console.log.

Could you please try it with insertAdjacentHTML instead of 'innerHTML' to just make sure or just use console.log.

像這樣;

document.getElementById('konsole').insertAdjacentHTML('beforeend',message);

這篇關于在 Electron 中操作 DOM的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創(chuàng)建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發(fā)技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 天天干成人网 | 午夜精品久久久久久 | 中文字幕在线一区二区三区 | 亚洲协和影视 | 日韩一区二区三区在线 | 久久精品一区 | 亚洲三级av | 亚洲三区在线观看 | 欧美一区二区三区视频 | 国产乱码精品一品二品 | 91精品国产91久久久久久最新 | 在线伊人网| 成人动漫视频网站 | 欧美男人天堂 | 国产大毛片 | 97伦理电影网 | 久久精品在线 | 亚洲综合成人网 | 在线欧美亚洲 | 国产传媒在线播放 | 一级毛片播放 | 毛片视频免费观看 | 一区二区不卡视频 | 黄色在线免费观看 | 麻豆成人在线视频 | 午夜黄色 | 久久狠狠| 国产视频中文字幕 | 一区二区三区视频在线观看 | 91精品国产自产精品男人的天堂 | h视频在线观看免费 | 久久久久久久久久性 | 国内精品久久影院 | 美女久久久久久久 | 免费一区在线观看 | 久久久久久综合 | 欧美极品在线播放 | 国外成人在线视频 | 91麻豆精品国产91久久久久久久久 | 四虎伊人 | 亚洲美女av网站 |