开启http-server
手机访问局域网地址
方法1:
使用alert代替console,如果alert不能确定错误原因,那么就在出问题的页面里监听onerroe错误事件,第一个参数是错误信息,第二个是出错误的文件名,第三个是第几行
window.onerror = function(message, file, row){
alert(message)
alert(file)
alert(row)
}
方法2:自己写一个consle区域
- 在页面中添加一个div用来显示console的内容,然后自己写一个console方法
<div id="consoleOutput" style="position: fixed; width: 100%; left: 0;bottom: 0;height: 100px; border:1px solid black; background: red;">
<script>
window.console = {
log(x){
let p = document.createElement('p')
p.innerText = x
consoleOutput.appendChild(p)
}
}
console.log('hi')
</script>
![](https://img.haomeiwen.com/i14361446/f848b5f99112599a.png)
- 使用cConsole库
2.1. 安装
npm install vconsole
2.2. 引入dist/vconsole.min.js
<script src = "..node_modules/vconsole/dist/vconsole.min.js"></script>
2.3. 使用
<script>
var vConsole = new VConsole()
console.log('Hello world')
</script>
网友评论