In front-end development, I often encounter the situation of waiting for background data, so record the mock basic syntax and common use, and urge myself!!
Mock syntax
The rules for each piece of data in the mock consist of three parts: Attribute name | generate rules: ‘name | min – Max’ attribute values: value ‘name | count’ : the value ‘name | min – Max’. The dmin – on3dmax: value ‘name | count’. Dmin – on3dmax: value ‘name | count’. Dcount: value ‘name | + step’ : the value attribute value can be a placeholder, generate rules depend on attribute value, attribute values also specifies initial values and types
String
‘test1 | 1-3’, ‘123’ 123 string repetitions for 1-3 times, also can change the 1-3 to specified number, such as 5
Number
‘test2 | 1-10.2-5’ : 1-10 of 20 refers to the maximum and minimum values, 2-5 refers to at least keep two, retained for a maximum period of five to 20 refers to the Number/type
‘test3 |’ 5.3: thirty five refers to the integer part 5, 3 refers to the decimal part three reserved
‘test4 | + 5’ : 10 + 5 at a time, the initial value of 10 (local test has been 10, somehow not stack)
Boolean
‘test5 | 1-4’ : true to true probability is 1 / (1 + 4), the probability of false to 4 / (1 + 4), is the value of the probability is min / + smax (min),! The value of Max/min and Max)
‘test6 | 3’ : true to true probability for 3 / (1 + 3), the probability of false is 1 / (1 + 3), which is the probability of the value of the count/(1 + count)
Object
‘name | min – Max’ : value take min, at least up to Max
‘name | count’ : the value to count from the Object
Array
The name ‘| 1’ : the value from the array a
‘name | count’ : the value in the count! =1, the array repeats count times
‘name | + 1’ : take the subscript value + 1 digital back in turn (local test no effect)
‘name | min – Max’ : the value repeat value is min, at least at most a Max
Function
‘name’:function() takes the return value of function
'test10': function () {
return1 + 2}Copy the code
regular
‘name’:regexp takes the return value of the re
'test11': /[a-z]/
Copy the code
The mock placeholder
1. Random string(type and digit) @string(lower,10) Type: lower: lowercase letter Upper: uppercase letter number: number
2. Random int (lower limit, upper limit) @integer(60,100)
3. Random Boolean @boolean
4. Random float/double (upper limit, lower limit) @float(60,100)
5. Random date (YYYY-MM-DD) @date
6. Random time (hh:mm:ss) @time
7. Random date + time (YYYY-MM-DD hh:mm:ss) @date
8. Current date + time (YYYY-MM-DD hh:mm:ss) @now
9. Random image placeholder to generate an image link @image(200*100)
10. Random color (# 79f2AC) @color
11. Long text (English) @ Paragraph
12. Long text (Chinese) @cparagraph
13. Common special formats @URL link @domain domain name @email mailbox @IP IP @region (East China, South China….) @province @city @county @zip @guID random guID @id random ID(Long)