发送请求时showLoading(), 请求失败hideLoading
// 当前正在请求的数量 let requestCount = 0 // 显示loading function showLoading () { if (requestCount === 0) { var dom = document.createElement('div') dom.setAttribute('id', 'loading') document.body.appendChild(dom) ReactDOM.render(<Spin tip="加载中..." size="large"/>, dom) } requestCount++ } // 隐藏loading function hideLoading () { requestCount-- if (requestCount === 0) { document.body.removeChild(document.getElementById('loading')) } }写在全局的loading样式
#loading { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(250, 250, 250, 0.65); display: flex; align-items: center; justify-content: center; z-index: 9999; font-size: 20px; }
