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你的獲取,但基本上它應該爲反應網站工作。 –