mockjs(二)——basic

布尔值的返回

Random.boolean( min?, max?, current? )

说明:

  1. min(可选),计算公式:min / (min + max)
  2. max(可选),计算公式:max / (min + max)
  3. current(可选),计算公式:Math.random() >= 0.5

随机自然数的返回

Random.natural( min?, max? )

说明:

  1. min(可选),随机自然数的最小值。默认值为0
  2. max(可选),随机自然数的最大值。默认值为9007199254740992

随机整数的返回

Random.integer( min?, max? )

说明:

  1. min(可选),随机自然数的最小值。默认值为-9007199254740992
  2. max(可选),随机自然数的最大值。默认值为9007199254740992

随机浮点数的返回

Random.float( min?, max?, dmin?, dmax? )

说明:

  1. min(可选),随机自然数的最小值。默认值为-9007199254740992
  2. max(可选),随机自然数的最大值。默认值为9007199254740992
  3. dmin(可选),小数部分位数的最小值。默认值为 0。
  4. dmax(可选),小数部分位数的最大值。默认值为 17。

随机字符的返回

Random.character( pool? )

说明:

  1. pool(可选),字符池,将从中选择一个字符返回。

随机字符串的返回

Random.string( pool?, min?, max? )

说明:

  1. pool(可选),字符池,将从中选择一个字符返回。
  2. min(可选),随机字符串的最小长度。默认值为 3。
  3. max(可选),随机字符串的最大长度。默认值为 7。

整型数组的返回

Random.range( start?, stop, step? )

说明:

1. start(必选),数组中整数的起始值。
2. stop(可选),数组中整数的结束值(不包含在返回值中)。
3. step(可选),数组中整数之间的步长。

随机日期字符串

Random.date( format? )

说明:

  1. format(可选),生成的日期字符串的格式。默认值为yyyy-MM-dd

随机时间字符串的返回

Random.time( format? )

说明:

  1. format(可选),生成的时间字符串的格式。默认值为 HH:mm:ss

占位符选择

Format Description Example
yyyy A full numeric representation of a year, 4 digits 1999 or 2003
yy A two digit representation of a year 99 or 03
y A two digit representation of a year 99 or 03
MM Numeric representation of a month, with leading zeros 01 to 12
M Numeric representation of a month, without leading zeros 1 to 12
dd Day of the month, 2 digits with leading zeros 01 to 31
d Day of the month without leading zeros 1 to 31
HH 24-hour format of an hour with leading zeros 00 to 23
H 24-hour format of an hour without leading zeros 0 to 23
hh 12-hour format of an hour without leading zeros 1 to 12
h 12-hour format of an hour with leading zeros 01 to 12
mm Minutes, with leading zeros 00 to 59
m Minutes, without leading zeros 0 to 59
ss Seconds, with leading zeros 00 to 59
s Seconds, without leading zeros 0 to 59
SS Milliseconds, with leading zeros 000 to 999
S Milliseconds, without leading zeros 0 to 999
A Uppercase Ante meridiem and Post meridiem AM or PM
a Lowercase Ante meridiem and Post meridiem am or pm
T Milliseconds, since 1970-1-1 00:00:00 UTC 759883437303

当前日期和时间字符串的返回

Random.now( unit?, format? )

说明:

  1. unit(可选),时间单位,用于对当前日期和时间进行格式化。可选值有:year、month、week、day、hour、minute、second、week,默认不会格式化。
  2. format(可选),生成的日期和时间字符串的格式。默认值为 yyyy-MM-dd HH:mm:ss

猜你喜欢

转载自blog.csdn.net/a839371666/article/details/80539190