0
我需要在iframe中显示html页面。我使用获取获取内容,因为该页面具有身份验证。我没有收到任何错误,我没有看到任何内容太reactjs iframe不显示html
someFunc() {
const myIframe = this.refs.myIframe;
fetch('http://example.com/example.html', {
method: 'GET',
headers: {
'Content-Type': 'text/html',
'Authorization': 'Basic xyz'
}
}).then(function(response) {
return response.text();
}).then(function(text){
//assign srcDoc to text
return <iframe srcDoc={text}></iframe>;
});
}
render() {
return (<div>{this.someFunc()}</div>)
}
我感动componentDidMount内提取和设置的孩子的状态,但我仍然没有看到iframe中。里面渲染我做{this.state.child} – shresthaal
好的,我会做一个codepen。 –
我编辑它,我有问题,因为Cors你的获取,但基本上它应该为反应网站工作。 –