vConsole 动态加载查看日志


vConsole 动态加载查看日志

https://github.com/Tencent/vConsole

https://www.npmjs.com/package/vconsole

有些情况,需要在线上环境进行某些功能的联调,为了不影响线上用户,可以把需要联调的功能隐藏;并在特定条件下触发,方便开发人员联调。

vConsole 日志是个十分方便的查看日志工具,可以在条件达成时触发加载这个日志,进行问题排查:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let jq = document.createElement('script');
jq.type = 'text/javascript';
jq.src = 'vconsole.min.js';
let node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(jq, node);
this.initCount = 0;
this.initInterval = setInterval(() => {
this.initCount++;
if (this.initCount > 10) clearInterval(this.initInterval);
if (typeof VConsole === 'undefined') return;
// 加载js成功后打开vconsole
window.vConsole = new VConsole();
clearInterval(this.initInterval);
}, 1000);