mock.js简单使用方法

>> npm install mock.js -D

>> 在页面中引入mock.js模块

>> 创建mock.js数据模板

```

let template = {

 'title': 'demo title',

 'string1|1-10': '@_@',

 'string2|3': '& ',

 'number1|+1': 100,

 'number2|1-100,

 'number3|1-100.1-10': 1

}

let data = Mock.mock(template)

Mock.mock(/^

https:\/\/wm.51shaoxi.cn\/api\/preorder\/roominfo/, template) // 符合正则规则的请求都能被拦截
 
$.ajax({    // 请求将被拦截,返回定义好的template的数据格式
 url: 'https://wm.51shaoxi.cn/api/preorder/roominfo',
 data: {
  'store_id': 100000055,
  'room_id': 100000014
 },
 type: 'get',
 dataType: 'json',
 success: function (res) {
  console.log(res)
 }
})

```

posted @ 2017-10-23 15:43  翩然雪海间  阅读(692)  评论(0编辑  收藏  举报