class Loading extends React.Component{
render(){
return (
<div>loading</div>
)
}
}
let node = null
const loading = {
show(){
node = document.createElement('div')
document.body.appendChild(node)
ReactDOM.render(<Loading/>,node)
},
hide(){
if(node){
ReactDOM.unmountComponentAtNode(node)
document.body.removeChild(node)
}
}
}
export default loading
调用时,先import 再loading.show() loading.hide()
一般这种方法,常用来写:loading,input,confirm,tooltip,message组件