componentDidMount是組件確實渲染成了dom后觸發,如果我在這時候append一個絕對定位top0的有顏色的div,預期效果應該是先顯示react組件,后立馬顯示紅色div但是實際是直接顯示紅色div了,都沒有閃一下的效果,這是為何?class App extends Component { constructor(){ super(); } componentDidMount() { const div=document.createElement('div'); div.style='position:absolute;height:100px;width:100vw;background:blue;top:0'; document.body.appendChild(div) } render(){ return ( <div style={{background:'red'}}>hello world</div> ) }}
react componentDidMount時機問題
慕無忌1623718
2019-03-14 14:15:59