gpt4 book ai didi

javascript - 使用 React 定期重新加载 iframe 的最佳方法是什么?

转载 作者:行者123 更新时间:2023-11-30 11:44:07 31 4
gpt4 key购买 nike

我正在使用 React 构建网页,这意味着我无法直接操作 DOM。我已经尝试通过更新 url 状态来重新加载我的 iframe,但这似乎并没有重新加载页面。这是我试过的州代码。

componentDidMount: function() {
setInterval(function(){
this.setState({currentUrl:currentUrl});
}.bind(this), 1000);
},
getInitialState: function() {
return {defaultUrl:this.props.graph.url, currentUrl:this.props.graph.url};
},
render() {
// render the graph iframe
return (
<iframe src={this.state.currentUrl} id={this.props.graph.url} style={this.props.style} width={this.props.width} height={this.props.graph_height} />
)
}

最佳答案

更改组件的关键属性例如:

this.state = {iframeKey: 0};

setInterval(() => this.setState(s => ({iframeKey: s.iframeKey + 1})), 1000);

<Iframe key={this.state.iframeKey} url={some url}/>

关于javascript - 使用 React 定期重新加载 iframe 的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41576794/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com