forked from Tencent/vConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
Tutorial | ||
============================== | ||
|
||
## Installation | ||
|
||
### 1. Download | ||
|
||
Download file `dist/vconsole.min.js` to your project's directory. | ||
|
||
Or, install via `npm` : | ||
|
||
``` | ||
npm install vconsole | ||
``` | ||
|
||
### 2. Import | ||
|
||
(1) Under non-AMD/CMD rule, insert vConsole into `<head>`. To support further features, insert vConsole into `<head>` rather than `</body>` is a better choice. | ||
|
||
```html | ||
<head> | ||
<script src="path/to/vconsole.min.js"></script> | ||
</head> | ||
``` | ||
|
||
(2) Under AMD/CMD rule, use `require()` to import vConsole. | ||
|
||
```javascript | ||
var vConsole = require('path/to/vconsole.min.js'); | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
### Print logs | ||
|
||
Use the methods of `console` to print logs, just like what you do at desktop browsers: | ||
|
||
```javascript | ||
console.log('Hello World'); | ||
``` | ||
|
||
When vConsole is not loaded, logs will be printed to native console. After importing vConsole, logs will be printed to both front-end console and native console. | ||
|
||
|
||
### Styles | ||
|
||
5 types of log method are supported, with different styles: | ||
|
||
```javascript | ||
console.log('foo'); // black word, white bakcground | ||
console.info('bar'); // purple word, white background | ||
console.debug('oh'); // orange word, white background | ||
console.warn('foo'); // orange word, yellow background | ||
console.error('bar'); // red word, pink background | ||
``` | ||
|
||
|
||
### Formatted object / array | ||
|
||
Object or Array variable will be printed as formatted JSON: | ||
|
||
```javascript | ||
var obj = {}; | ||
obj.foo = 'bar'; | ||
console.log(obj); | ||
/* | ||
Object | ||
{ | ||
foo: "bar" | ||
} | ||
*/ | ||
``` | ||
|
||
|
||
### Polymorphic | ||
|
||
Multiple arguments are supported, each variable will be divided by a space: | ||
|
||
```javascript | ||
var uid = 233; | ||
console.log('UserID:', uid); // UserID: 233 | ||
``` | ||
|
||
|
||
### Special format | ||
|
||
Use `[default|system|...]` string to print logs to specific panel: | ||
|
||
```javascript | ||
// [xxx] must be at the beginning of a log | ||
console.log('[system]', 'foo'); | ||
console.log('[system] bar'); | ||
// foo & bar will be printed to system panel | ||
``` | ||
|
||
Supported panels: | ||
|
||
``` | ||
[default] Log panel (default) | ||
[system] System panel | ||
``` | ||
|