移动端进行 console.log() 调试
一、需求
在 移动端进行开发的时候,往往没办法直接查看 console 的输出内容,而有时候又必须查看。
alert 太难用。
尤其是在 微信移动端开发的时候,很多错误 PC 是无法验证的。
因此 移动端 console 是刚需。
二、方案
1、自定义 对象输出
将 js 错误对象或者字符串打成 json 直接输出到一个 modal 中
这种方式我以前用过,可行,但是太麻烦
2、使用 vConsole
我最早使用 vConsole 的时候,是在小程序上使用的,那时候我还不知道 vConsole 开源了。
使用方式很简单:
在 dist 中的 vconsole.min.js
下载下来:
在 header 中引入 vconsole.min.js
<link href="vconsole.min.js">
在 js 最前面实例化 vConsole
const vConsole = new vConsole();
之后随便 console.log()
什么的都可以,不需要做其他的操作了。
效果:
官方的文档如下:
文章版权:Postbird-There I am , in the world more exciting!
本文链接:http://www.ptbird.cn/mobile-console-log.html
转载请注明文章原始出处 !
扫描二维码,在手机阅读!