-
Eruda——手机网页前端调试面板
-
实现类似于微信小程序的移动端调试效果。
<script src="http://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.2.0"></script>
<script>
// init vConsole
var vConsole = new VConsole();
console.log('Hello world');
</script>
github地址vConsole
然后你就可以在页面的右下角看到一个绿色的 vConsole,点开它就能使用了,整体界面和 Chrome 的控制台类似,非常方便!
不过,这样引入的话无论是在电脑上还是手机上,无论是站长和访客都能看到这个按钮。有点不太友好……
为此,我们可以采用下面的方法:
<script>
if ((location.href || '').indexOf('vconsole=true') > -1) {
document.write('<script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"><\/script>');
document.write('<script>new VConsole()<\/script>');
}
</script>
这样,正常访问网站时不会加载这个工具,仅当在网址后面加上 ?vconsole=true 时才会载入,按需开启,非常好用!