1.Mock.mock( template )
根據(jù)數(shù)據(jù)模板生成模擬數(shù)據(jù)冈钦。(具體語法見mock.js入門)
2.Mock.mock( rurl, template ) --厲害了哦
Mock.mock(/http:\/\/localhos\/login/, {
? ? 'list|1-10': [{
? ? ? ? 'id|+1': 1,
? ? ? ? 'email': '@EMAIL'
? ? }]
})
通過ajax請求生成數(shù)據(jù)的接口
$.ajax({? ? url: 'http://localhos/login',? ? dataType: 'json'? }).done(function(data, status, jqXHR){?
? ? $('<pre>').text(JSON.stringify(data, null, 4)).appendTo('body')
})
ajax獲取到數(shù)據(jù):
{
? ? "list": [
? ? ? ? {
? ? ? ? ? ? "id": 1,
? ? ? ? ? ? "email": "x.oxmxm@rlwisyowm.int"
? ? ? ? },
? ? ? ?{
? ? ? ? ? ? "id": 2,
? ? ? ? ? ? "email": "m.jmvq@fdjlqn.pw"
? ? ? ?}
? ? ]
}
3.Mock.mock( rurl, function( options ) )
記錄用于生成響應數(shù)據(jù)的函數(shù)。當攔截到匹配rurl的 Ajax 請求時浩蓉,函數(shù)function(options)將被執(zhí)行派继,并把執(zhí)行結果作為響應數(shù)據(jù)返回宾袜。
4.Mock.mock( rurl, rtype, template )
記錄數(shù)據(jù)模板。當攔截到匹配rurl和rtype的 Ajax 請求時驾窟,將根據(jù)數(shù)據(jù)模板template生成模擬數(shù)據(jù)庆猫,并作為響應數(shù)據(jù)返回。