// JS动态加载引入JS文件
// 1.调整标签位置
// 可以把 <script> 标签放到HTML文档的最后面,这样不影响页面加载。
// 2.动态创建script来加载
function loadJS(url, callback) {
var script = document.createElement('script'),
fn = callback || function () { };
script.type = 'text/javascript';
// IE
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState == 'loaded'
|| script.readyState == 'complete') {
script.onreadystatechange = null;
fn();
}
};
} else {
// 其他浏览器
script.onload = function () {
fn();
};
}
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
// 获取链接参数
function getParamsSearch() {
var url = window.location.search; //获取url中"?"符后的字串
var params = new Object();
if (url.indexOf("?") != -1) {
var str = url.substring(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
params[strs[i].split("=")[0]] = strs[i].split("=")[1];
}
}
return params;
}
var params = getParamsSearch()
console.log('params->', params)
if (params.debug == 1) {
loadJS('https://cloudm.oss-cn-hangzhou.aliyuncs.com/cdn/npm/vConsole/3.15.0/vconsole.min.js', function () {
//加载,并执行回调函数
console.log('动态引入js成功')
// 开启 vconsole
new VConsole();
});
}