判断一个脚本已经加载完毕的方法
export const appendScriptReady = (url, onReadyCallback) => { const targetScript = document.createElement('script') targetScript.type = 'text/javascript' if (targetScript.readyState) { // IE 6,7,8 targetScript.onreadystatechange = () => { if (targetScript.readyState === 'loaded' || targetScript.readyState === 'complete') { targetScript.onreadystatechange = null onReadyCallback() } } } else { // Not IE targetScript.onload = () => { onReadyCallback() } } targetScript.src = url document.head.appendChild(targetScript) }