有些时候想要开发环境显示console.log信息,但是生成环境不去显示这些信息,如何关闭?
原理:关闭log
console.log = function () {
return false;
}
复制代码
const getQueryStr = (name) => {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
};
/* 若链接后面带上参数 envFlag=monitor
* 则将 debug 置为true,否则置为false
*/
const monitor = 'monitor';
const envFlag = getQueryStr('envFlag');
let debug = monitor ? true : false;
if (envFlag === 'monitor' || process.env.NODE_ENV === 'development') {
console.log("%cNow You Can Console Log...", "color:red;font-size:18px;font-style:oblique;");
debug = monitor;
} else {
debug = '';
console.log = function () {
return false;
}
}
// 组件的显示或隐藏
const state = {debug: debug};
export const store = new vuex.Store({state, mutations});
复制代码
所有评论(0)