reactjs - 通过位于 REACT 中不同路径的另一个组件管理组件的重新加载
问题描述
我的反应应用程序遇到困难。我有一个循环调用 iframe 的组件,使它们可见几秒钟。“重新加载”通过一个按钮进行。但是,我需要从另一个页面检查 iframe 重新加载。例如,创建一个“configuration.js”组件,其中有一个按钮,一旦单击,就会激活“重新加载”功能。然而,iframe 重新加载在“http://localhost:3000/simulatoretv”中呈现,而启动重新加载的按钮出现在“http://localhost:3000/configurator”中。我希望我已经足够清楚了。我附上了组件“广告”的脚本,通过它我运行 iframe 的重新加载。
import React, { Component } from "react";
class Pubblicità extends Component {
state = {
index: 0,
iframeSrcs: ["/300x250", "/160x600", "/468x60"],
visibility: false
};
reload = () => {
const iframeLength = this.state.iframeSrcs.length;
if (this.state.index < iframeLength) {
this.setState({
index: this.state.index + 1,
visibility: true
});
} else {
this.setState({ index: 0, visibility: true }); //starting again
}
setTimeout(() => {
this.setState({ visibility: false });
}, 15000);
};
render() {
return (
<div>
<button
style={{
position: "absolute",
left: 0,
right: 0,
top: 500
}}
onClick={this.reload}
>
pubblicità
</button>
{this.state.visibility ? (
<iframe
style={{
position: "absolute",
left: 500,
right: 0,
top: 10
}}
key={this.state.index}
title="AdSlot"
src={this.state.iframeSrcs[this.state.index]}
height="100%"
width="100%"
scrolling="no"
frameborder="0"
/>
) : (
""
)}
</div>
);
}
}
export default Pubblicità;
这是另一个组件,我希望“Pubblicità”组件显示受控的 iframe。这个组件的路由是“http://localhost:3000/platformOTT”。
import React, { Component } from "react";
import SimulatoreTV from "./SimulatoreTV";
import Pubblicità from "./Pubblicità";
class PiattaformaOTT extends Component {
render() {
return (
<div>
<SimulatoreTV />
<Pubblicità />
</div>
);
}
}
export default PiattaformaOTT;
感谢那些想帮助我的人。
解决方案
推荐阅读
- cuda - 无法在 Ubuntu 16.04 上安装 CUDA
- flutter - 在颤动中滚动到水平ListView上的某个索引
- javascript - 如何将 NPM 包导入浏览器的控制台
- ios - React Native iOS 的无效注册
- java - 将 /Date(XXXXXX)/ 转换为像 YYYY-MM-DD 这样的日期
- amazon-web-services - 使用 AWS API Gateway 继承 OpenAPI / Swagger 模型
- javascript - 我会解释这个函数 .map ()
- java - 如何将 AWS KMS 与 java sdk 结合使用,以便能够将 IAM 凭证解析到 ECS 环境中?
- cognos - 突发 COGNOS 报告包括 CC 或 BCC 可能吗?
- android - 附近连接发现在 Android10 上引发错误 8036