This is the fifth day of my participation in Gwen Challenge
VsCode integration terminal Cmder(4) Introduces VsCode integration terminal Cmder, a more convenient command line tool -, –
Writing arrangement is not easy, diligent big hand son, love small praise point just for reference, according to the need to eat, insufficient, welcome all big guy generous comments, supplement and perfect, welcome to share
This article studies the code specifications used in working practice for reference only
preface
In the process of multi-team collaboration, the code is not standardized, and colleagues silently cry.
Do you have trouble understanding his code or just seem to struggle with it? When you take over the last coder’s code, you need to change his code and you don’t know where to start
Some big factories are standardized
Most companies, work teams, and large factories have a clear code specification document, organized as follows:
# | Code specification document |
---|---|
1 | Vue official Style Guide |
2 | JavaScript coding specification |
3 | Bump Lab – Front-end code specification |
4 | TGideas Tencent games |
5 | baidu |
6 | Netease Coding Specification |
7 | ES6 |
8 | Eslint |
9 | Prettier.io |
10 | JavaScript |
. | . |
The first Vue official specification in the table above, > the following describes some of the specifications developed in real projects using Vue2
First, annotation specification
In the process of multi-team collaboration, the code is not standardized, and colleagues silently cry. Good code practice is clear code comments
- Usage instructions for common components
- Description of important functions or classes in a component
- Complex business logic processing instructions
- Special case code handling instructions, for special purpose variables in the code, the existence of critical values, used in the function
hack
, the use of a certain algorithm or ideas need to be annotated description - The comment block must be
/** (at least two asterisks) begins with **/
- Single-line comments are used
//
Second, coding specifications
- use
ES6
Style coded source code- Define variables using
let
, define constants to useconst
- use
export
.import
modular
- Define variables using
- component
props
atomization- Provide default values
- use
type
Attribute verification type - use
props
Check this firstprop
If there is a
- avoid
this.$parent
- Use caution
this.$refs
- Don’t need to
this
Assigned tocomponent
variable - Debugging information
console.log() debugger
Delete immediately after use
Component naming conventions
- Meaningful nouns, short and readable
- Start with lowercase and name with a dash
- Common component names are simply spelled with the company name as a namespace (app-xx.vue)
- The folder name is mainly named after the functional module representative
Iv. Placing order of VUE method
- The components template
- The props parent component passes information
- data
- created
- mounted
- activited
- update
- beforeRouteUpdate
- metods
- filter
- computed
- watch
5. HTML specification
-
The structural order and the visual order are basically the same
-
Separate structure, performance, and behavior. Avoid inlining
-
Keep a nice clean tree structure
-
Structurally, if you can write side by side, do not nest.
- If I could write it as
<div></div><div></div>
So don’t write it nested<div><div></div></div>
- If I could write it as
-
If the structure already meets the visual and semantic requirements, then don’t have extra redundant structure.
- Such as
<div><h2></h2></div>
That satisfies the requirement, so don’t write it again<div><div><h2></h2></div></div>
- Such as
-
Don’t reference too many class names on a tag, as few as possible.
- For example, don’t:
<div class = "class1 class2 class3" > </ div>
- For example, don’t:
-
For a semantically internal tag, avoid using a className.
- For example, in a list like this, the ITM in the LI tag should be removed:
<ul class="m-help"><li class="itm"></li><li class="itm"></li></ul>
- For example, in a list like this, the ITM in the LI tag should be removed:
CSS specifications
-
Naming rules
- Use the class selector and discard the ID selector
- NEC special characters: “-” hyphen
- Classification naming method: use a single letter +”-” prefix
- Naming should be concise without losing semantics
-
Code format
- Selectors, properties, and values are all lowercase
- Write a selector definition in a single line
- The last value also ends with a semicolon
- Omit the value for
0
At the time of the unit - Use single quotes
- Write in order of importance
- Comment format:
/* Comment the text */
-
Selector order
- Please consider the following order:
- From large to small (depending on the range of the selector)
- From low to high (in order of rank)
- From first to last (in structural order)
- From father to child (depending on the structure of nesting)
Here list some configuration, only for reference, throw a brick to attract jade, have got it?
There was no warning this time
Below I will update [I haven’t decided yet] -, -.. Please look forward to thinking about it tomorrow.. hahah