effect
Intercept ajax to generate random data
- installation
npm install mockjs -D
- Import, it is recommended to write in main.js
import Mock from 'mock'
const Mock = require('mock')
- Configure interception
- Need to write a separate file and import it in the main.js file
Mock.mock('requestPath','GET',function(){
return {
name:'111'}
})
-
Parameter 1 Intercepted request interface path (can be regular expression)
-
Parameter 2 The request method to intercept, if not written, all will be intercepted by default
-
Parameter 3 The operation after interception, the returned fake data can be written here
-
When using this interface, just use it directly, and it will return false data directly.
Regular placement
- Character class
'数据名称 | 最小-最大': "字符串" // 返回一个字符串,个数在区间内随机
"数据名称":"@cname" // 一个随机的人名
- Numbers
数据名称 | 最小值-最大值": 出现几次
数据名称 | 数字.小数点后位数": 出现几次
- Picture category
"数据名称":function(){
return Mock.Random.dataImage("200x100"); //图片宽高
},
- mailbox
"数据名称":"@email" // 一个随机i的邮箱
- position
"数据名称":"@county(true)"