程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了尝试使用按钮从渲染器内部生成子进程大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决尝试使用按钮从渲染器内部生成子进程?

开发过程中遇到尝试使用按钮从渲染器内部生成子进程的问题如何解决?下面主要结合日常开发的经验,给出你关于尝试使用按钮从渲染器内部生成子进程的解决方法建议,希望对你解决尝试使用按钮从渲染器内部生成子进程有所启发或帮助;

我正在开发一个电子应用程序,我想在其中启动子节点进程(以运行 discord.Js 机器人)。

我有以下代码:

index.HTML

<tr>
    <th class="title-bar-cell" style="text-align: left;">
        <i onclick="window.close()" ID="close-button" class="far fa-window-close"></i>
        <i onclick="ipcRenderer.send('minimize')" ID="minimize-button" class="far fa-window-minimize"></i>
        <p ID="title-bar-text">Toggle Control Panel</p>
    </th>
    <th class="title-bar-cell right-indent" style="text-align: right;">
        <i ID="new-bot-button" class="fas fa-plus bar-icon"></i>
        <i ID="SELEct-bot-button" class="fas fa-Box-open bar-icon"></i>
        <i ID="start-bot-button" class="fas fa-play bar-icon"></i>
        <i ID="stop-bot-button" class="fas fa-stop bar-icon"></i>
        <i ID="about-button" class="fas fa-info bar-icon"></i>
    </th>
</tr>

botController.Js

document.getElementByID('start-bot-button').addEventListener('click',() => {
  ipcRenderer.send('startBot');
})

但是,JavaScript 抛出一个错误,指出我无法将属性 addEventListener 添加到 null。为什么?

另外,我需要为 ipcRenderer 导入一些东西吗?或者只是给了。

解决方法

您在 HTML 中的哪个位置加载 botController.js?如果您在 <head> 标记中加载它,请将其删除并将其放在 HTML 正文的底部(标记内)。它可能返回 null,因为 DOM 尚未加载。

还要使用 ipcRenderer,请将以下行添加到 botController.js 的顶部:

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

大佬总结

以上是大佬教程为你收集整理的尝试使用按钮从渲染器内部生成子进程全部内容,希望文章能够帮你解决尝试使用按钮从渲染器内部生成子进程所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。