安装 Mock
- 在终端输入以下命令:
cnpm install mockjs
- 在
vue
文件,引入Mock
:
var Mock = require('mockjs')
Mock 语法
7 种规则:
'name|min-max':value
'name|count':value
'name|min-max.dmin-dmax':value
'name|min-max.dcount':value
'name|count.dmin-dmax':value
'name|count.dcount':value
'name|+step':value
Mock 样例
1. 样例1:
var str1 = Mock.mock({
'number1|1-100.1-10':1,
'number2|123.1-10':1,
'number3|123.3':1,
'number4|123.10':1.123
});
console.log(str1);
//输出结果:{number1: 21.8536428704, number2: 123.594, number3: 123.376, number4: 123.1235243155}
2. 样例2:
var str2 = Mock.mock({
'regexp1':/[a-z][A-Z][0-9]/,
'regexp2':/\w\W\s\S\d\D/,
'regexp3':/\d{5,10}/
});
console.log(str2);
//输出结果:{regexp1: "iU1", regexp2: "H" 65S", regexp3: "2227827"}
网友评论