• 03----Mock.mock() 生成接口,随机数据


    Mock.mock( url, type, template|function( options ) )

    url:请求地址
    type:请求的类型
    function:回调
    temlate:生成的数据

    Mock.mock( template )

    根据数据模板生成模拟数据。 

    Mock.mock( url, template )

    记录数据模板。
    当拦截到匹配 url 的 Ajax 请求时,将根据数据模板 template 生成模拟数据,并作为响应数据返回。

    Mock.mock( url, function( options ) )

    记录用于生成响应数据的函数。
    当拦截到匹配 url 的 Ajax 请求时,函数 function(options) 将被执行,并把执行结果作为响应数据返回。

    Mock.mock( url, type, template )

    记录数据模板。

    当拦截到匹配 url 和 type 的 Ajax 请求时,将根据数据模板 template 生成模拟数据,并作为响应数据返回。

    Mock.mock( url, type, function( options ) )

    记录用于生成响应数据的函数。

    当拦截到匹配 url 和 type 的 Ajax 请求时,函数 function(options) 将被执行,并把执行结果作为响应数据返回。

    url

    可选。
    
    表示需要拦截的 URL,可以是 URL 字符串或 URL 正则。
    例如
    正则://domain/list.json/

    字符串:'/domian/list.json'

    type

    可选。
    
    表示需要拦截的 Ajax 请求类型。例如 GET、POST、PUT、DELETE 等。

    template

    可选。
    
    表示数据模板,可以是对象或字符串。例如 { 'data|1-10':[{}] }、'@EMAIL'

    function(options)

    可选。
    
    表示用于生成响应数据的函数。

    options

    指向本次请求的 Ajax 选项集,含有 url、type 和 body 三个属性
  • 相关阅读:
    NSIS 资料
    git 强制刷新,放弃更改
    Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8
    …gen already exists but is not a source folder. Convert to a source folder or rename it [closed]
    eclipse
    Timeout in android httpclient
    git command
    L1-032. Left-pad
    L1-030. 一帮一
    L1-028. 判断素数
  • 原文地址:https://www.cnblogs.com/SRH151219/p/10547379.html
Copyright © 2020-2023  润新知