微信公众号开启开发者工具DevTools
·
vConsole 是一个由腾讯推出的轻量、可拓展的前端开发者工具,专为移动网页调试设计,旨在解决在手机上无法直接使用浏览器开发者工具(如 Chrome DevTools)的痛点。
下载
npm install vconsole
使用
import VConsole from "vconsole"
new VConsole()
其他条件判断
// 判断是否为微信浏览器
export const ifWXWEB = () => {
// #ifdef H5
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('micromessenger') !== -1) {
// console.log('当前页面在微信中打开');
return true
} else {
// console.log('当前页面不在微信中打开');
return false
}
// #endif
return false
}
// 微信浏览器打开,开发环境或者对应token用户开启
export const consoleDevelop = () => {
// new VConsole()
if (ifWXWEB() && process.env.NODE_ENV === 'development') {
new VConsole()
return
}
if (ifWXWEB() && developToken.includes(getToken())) {
new VConsole()
}
}
// 微信浏览器打开,地址栏有 vconsole=1 时开启
export const createConsoleForce = () => {
// #ifdef H5
if (window.navigator.userAgent.toLowerCase().indexOf('micromessenger') === -1) return
const reg = /[?&]vconsole=([^&#]*)/
const match = reg.exec(window.location.href)
const value = match && match[1]
if (value !== '1') {
return
}
new VConsole()
// #endif
}
更多推荐
所有评论(0)