This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

Global annotation console debugging when vue is packaged

We use a lot of console debugging during development, and we don’t want to comment it all out when we’re done, so we can add the following code to the webpack.prod.conf.js file in the build folder when we’re packing

New UglifyJsPlugin({uglifyOptions: {compress: {warnings: false, // filter console.log-start drop_console: True, pure_funcs: ['. The console log '] / / filter the console log - end}}, sourceMap: config. Build. ProductionSourceMap, parallel: true }),Copy the code

The type of the console

console.table

This is an array structure that can be printed out as a table to display on the console

let arr = [ { id: "46f7c6ba-b4ca-4843-b5d1-76399d1ac52a", parentId: A80ff169-d6f6-4752-b980-fd818240410f ", attributeName1: "color ",}, {id: "46f7c6ba-b4ca-4843-b5d1-76399d1ac52a", parentId: "a80ff169-d6f6-4752-b980-fd818240410f", attributeName1: "Color ",}, {id:" 46f7c6ba-b4ca-4843-b521-76399d1ac52a ", parentId: "A80ff169-d6f6-4752-b980-fd818240410f ", attributeName1:" color ",}] console.table(arr);Copy the code

The results are as follows

console.error()

With this method, you can see an error message at the control point

Console. error(‘ Error message ‘)

console.log()

This is one of the most common ways to print data. It can be used to print all kinds of information, including returned data, pure data, and function judgments

let num = 0
let num2 = 1
console.log(num>num2)
console.log(num===num2)
console.log(num<num2)
Copy the code

The console. Time () with the console. TimeEnd ()

This is a print method of timing, time() is the start of the timing, timeEnd() is the end of the timing, see the operation and result below

Console. time(' timer 1'); for (var i = 0; i < 10; i++) { for (var j = 0; j < 10; J++) {}} console.timeEnd(' timer 1');Copy the code

console.warn()

This is a warning print message method, and the error type is similar, but the color of the prompt is different

console.count()

This is one way to print a count


(function() {
  for (var i = 0; i < 10; i++) { 
    console.count('count'); 
  }
})();

Copy the code