A simulation data generator

Related tags

Data Structure Mock
Overview

Mock.js

Build Status

Mock.js is a simulation data generator to help the front-end to develop and prototype separate from the back-end progress and reduce some monotony particularly while writing automated tests.

The official site: http://mockjs.com

Features

  • Generate simulated data according to the data template
  • Provide request/response mocking for ajax requests
  • Generate simulated data according to HTML-based templates

This library is loosely inspired by Elijah Manor's post Mocking Introduction, mennovanslooten/mockJSON, appendto/jquery-mockjax and victorquinn/chancejs.

Questions?

If you have any questions, please feel free to ask through New Issue.

Reporting an Issue

Make sure the problem you're addressing is reproducible. Use http://jsbin.com/ or http://jsfiddle.net/ to provide a test page. Indicate what browsers the issue can be reproduced in. What version of Mock.js is the issue reproducible in. Is it reproducible after updating to the latest version?

License

Mock.js is available under the terms of the MIT License.

Comments
  • 请问fetch能拦截吗?

    请问fetch能拦截吗?

    if(__DEV__){
            console.log(BASE_URLS[server] + path,method)
            // http://127.0.0.1:7586/api/order/v1/orders/1
            Mock.mock('http://127.0.0.1:7586'+BASE_URLS[server]+path, method, {
                "data|1-10":[{
                    "id|+1":1,
                    "name|1-5":"avcx"
                }]
            })
        }
    return new Promise((resolve, reject) => {
            fetch(url, {
                method: method,
                body: data,
                headers: {
                    ...contentType?{
                        "Content-Type": contentType
                    }:{},
                    "Accept-Language": utils.locale.get()
                },
                credentials: "same-origin"
            }).then(function(resp) {
                (format === "html"?resp.text():resp.json()).then(data => {
                    if (__DEV__) {
                        console.log(method, resp.url, data)
                    }
                    if (!resp.ok) {
                        reject({
                            type: failureType,
                            code: data.code || resp.status,
                            message: data.message || resp.statusText,
                            saveAs: saveAs,
                        })
                    }
    
                    resolve({
                        type: successType,
                        code: data.code || resp.status,
                        message: data.message || resp.statusText,
                        // Only select the wanted data
                        data: select(data, format),
                        total: data.data && data.data["total"]?data.data.total:0,
                        saveAs: saveAs
                    })
                }, error => console.log(error))
            }, function(error) {
                console.log("Network Failure", error.message) //=> String
                reject({
                    type: failureType,
                    code: 499,
                    message: error.message,
                })
            })
        })
    
    opened by JackieLs 8
  • Mock.toJSONSchema( template )

    Mock.toJSONSchema( template )

    规则映射

    | rule | String | Number | Boolean | Object | Array | Function | RegExp | | --- | --- | --- | --- | --- | --- | --- | --- | | min | √ | √ | √ | √ | √ | | √ | | max | √ | √ | √ | √ | √ | | √ | | dmin | | √ | | | | | | | dmax | | √ | | | | | | | step | | √ | | | | | |

    enhancement 
    opened by nuysoft 8
  • 数据结构的模板定义好了,可是需要重复,谁可以指导一下吗?

    数据结构的模板定义好了,可是需要重复,谁可以指导一下吗?

    // 数据格式:
        var template = {
          'data': {
            'eid': '@integer(10000,20000)', // 试卷ID
            'title': '@cparagraph(1)', // 试卷标题
            'intro': '@csentence(5,20)', // 试卷介绍
            'imgs': '@dataImage', // 试卷介绍用的图片
            'cost': '@integer(0,20)', // 答题所需消耗的分数
            'answered': '@integer(0,1)', // 当前用户是否已答过题,0=未答,1=已答。对于访客或get_answer=0时,不返回该项
            'questions': [{
              'id': '@integer(1000,2000)',
              'text': '@csentence(5,20)',
              'imgs': '@dataImage', // 问题附带的图片
              'opt_limit': '@integer(1,4)', // 允许提交的答案个数
              'options': [{
                'id': '@integer(100,200)', // 选项ID
                'text': '@csentence(3,5)', // 选项的文字描述
                'img': '@dataImage', // 选项的附图,如有多张图,以|隔开
                'selected': '@integer(0,1)', // 当前用户是否选择了该项,0为未选,1位已选。对于访客或get_answer=0时,不返回该项
                'count': '@integer(0,500)' // 总共多少人选了该项。对于访客或get_answer=0时,不返回该项
              }]
            }]
          },
          'errcode': 0,
          'msg': 'OK',
          'success': 'true'
        }
        var data = Mock.mock(template);
        console.log(data)
    

    以上是我的数据结构,可是希望 questions 这个数组里面重复若干次对象,希望options里面也重复若干次对象。。不知道怎么改这个数据结构

    opened by ringcrl 6
  • 如何继续发送ajax请求

    如何继续发送ajax请求

    mockjs很好用,大赞!

    使用过程,遇到以下场景,需根据头部决定是否拦截请求

    因为接口与前端并行开发,某些接口完成后,不再需要mock data,直接发送请求。

    请问mockjs是否支持该场景?应该怎么实现?

      Mock.mock(/index\.html/, function(options){
            var headers = options.headers, moduleName = headers["Module"];
            if(moduleName === "mainRecommend"){
                return mockMainRecommend();
            }else if (moduleName === "mainTop"){
                return mockMainList();
            }else{
                //继续发送ajax请求
            }
    }
    
    opened by daddybh 5
  • Mock.Random.dateImage() dont work in nodejs

    Mock.Random.dateImage() dont work in nodejs

      app.get('/foo', function (req, res) {
        var data = Mock.mock({
          "thumb": Mock.random.dataImage('200x100', 'test')
        });
        res.jsonp(data);
      });
      // mockjs: v0.1.4
      // nodejs: v0.10.28
    
    opened by DaniloShan 5
  • 关于滥改 Wiki 的公告:气死人了,请在 issues 中讨论过再修正

    关于滥改 Wiki 的公告:气死人了,请在 issues 中讨论过再修正

    @dianniu [email protected] @cuidingfeng [email protected]

    请不要直接在 Wiki 中提建议!!!

    你们这样改直接破坏了文档的内容!!!

    让其他人怎么读文档!!!

    愤怒!!!

    --- ### current
    +++ ### current--》建议默认值为true
    
    --- * Random.float( min, max, dmin )
    +++ * Random.float( min, max, dmin )==》建议第三个参数为length,即生成大于min小于max小数位为length的浮点数
    
    --- 4. _占位符_ 也可以引用 _数据模板_ 中的属性。
    +++ 4. _占位符_ 也可以引用 _数据模板_ 中的属性。-->(根据下一条,既然优先引用说明可以引用,此句冗余)
    
    --- ## Random.ip()
    +++ ## Random.ip()--->建议预留一个参数(生成内网ip)
    
    +++ # Mock.Random.extend
    
    +++ 没有介绍吗?
    
    opened by nuysoft 4
  • 带有自定义函数的复杂JSON,使用Mock.mock时报错

    带有自定义函数的复杂JSON,使用Mock.mock时报错

    请看看,某位客户的JSON,通过RAP生成了模板后,在Mock.mock时报错。

    {
        "extra": {
            "page": 1,
            "pagesize": 20,
            "totalpage": 1,
            "total": 10
        },
        "message": "\u64cd\u4f5c\u6210\u529f",
        "result": true,
        "code": 99999999,
        "data|2": [{
            "designer_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1,1)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10000';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "scene_name": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\u5546\u54c1\u6548\u679c\u6d4b\u8bd5\",\"\u5546\u54c1\u6548\u679c\u6d4b\u8bd5\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10001';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "in_shelf": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1,1)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10002';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "room_args": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"{\"1\":{\"id\":1,\"FOVx\":65.97752238227275,\"FOVy\":40.117807,\"Position\":{\"x\":3.368628,\"y\":-2.995035,\"z\":1.4},\"Quaternion\":{\"x\":0.722453,\"y\":0.001152,\"z\":-0.001102,\"w\":-0.691419},\"angleX\":107.922626,\"angleY\":45.132237,\"dragAngleX\":107.922626,\"dragAngleY\":45.132237,\"isPanorama\":true,\"dragAngleLeft\":52,\"dragAngleRight\":33,\"dragAngleUp\":22,\"dragAngleDown\":22,\"exposureBias\":1,\"QuaternionNew\":{\"x\":-0.7155519334704465,\"y\":-0.08015251829528554,\"z\":0.07724920278482071,\"w\":0.6896329204632993}},\"room\":{\"sizeX\":13.4,\"sizeY\":7.2,\"sizeZ\":3.2,\"isPanorama\":true}}\",\"{\"1\":{\"id\":1,\"FOVx\":65.97752238227275,\"FOVy\":40.117807,\"Position\":{\"x\":3.368628,\"y\":-2.995035,\"z\":1.4},\"Quaternion\":{\"x\":0.722453,\"y\":0.001152,\"z\":-0.001102,\"w\":-0.691419},\"angleX\":107.922626,\"angleY\":45.132237,\"dragAngleX\":107.922626,\"dragAngleY\":45.132237,\"isPanorama\":true,\"dragAngleLeft\":52,\"dragAngleRight\":33,\"dragAngleUp\":22,\"dragAngleDown\":22,\"exposureBias\":1,\"QuaternionNew\":{\"x\":-0.7155519334704465,\"y\":-0.08015251829528554,\"z\":0.07724920278482071,\"w\":0.6896329204632993}},\"room\":{\"sizeX\":13.4,\"sizeY\":7.2,\"sizeZ\":3.2,\"isPanorama\":true}}\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10003';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "style_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1,1)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10004';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "creator": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10005';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "pics_path": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10006';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "user_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10007';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "adv_bottom": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10008';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "haspics": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10009';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "isrecommend": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10010';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "root_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10011';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "desc": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"<p>12<\/p>\",\"<p>12<\/p>\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10012';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "model_info": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"[{\"id\":157,\"position\":{\"x\":0.8290811648136097,\"y\":2.773665489427823,\"z\":0.3800000000000001},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.06920367457323079},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.034594932977462294,\"w\":0.9994014161548326}},{\"id\":37,\"position\":{\"x\":3.211819238806907,\"y\":0.8361365252640024,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-1.5207963275941434},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.6892099939523402,\"w\":0.72456164971396}},{\"id\":37,\"position\":{\"x\":2.1239044442716355,\"y\":0.7270494947133531,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":1.809203666420212},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.7861791507359865,\"w\":0.6179986593416227}},{\"id\":64,\"position\":{\"x\":1.2854428247993726,\"y\":2.1088075631936727,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-1.5707963267948963},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.7071067811865475,\"w\":0.7071067811865477}},{\"id\":160,\"position\":{\"x\":2.5180308423769353,\"y\":1.7037948087943773,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.0007963267961379878},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.00039816338754858187,\"w\":0.9999999207329553}},{\"id\":110,\"position\":{\"x\":4.363383838660308,\"y\":1.8446611590397413,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.6207963216517365},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.30543779417332834,\"w\":0.9522120320026057}},{\"id\":150,\"position\":{\"x\":0.38423754919784114,\"y\":2.8821267664956207,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.12920367633817348},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.06455691268644366,\"w\":0.9979140268702484}},{\"id\":179,\"position\":{\"x\":1.6566218773145178,\"y\":0.6982262358268683,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.3207963322474933},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.15971127443568203,\"w\":0.9871637700088726}},{\"id\":116,\"position\":{\"x\":0.7876551977953973,\"y\":1.0447069865075296,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.4692036732051035},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.2324557474516606,\"w\":0.9726069737960394}},{\"id\":123,\"position\":{\"x\":0.2772290873919028,\"y\":0.450067813046513,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.9792036732051036},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.47027453822665294,\"w\":0.8825201746678136}}]\",\"[{\"id\":157,\"position\":{\"x\":0.8290811648136097,\"y\":2.773665489427823,\"z\":0.3800000000000001},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.06920367457323079},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.034594932977462294,\"w\":0.9994014161548326}},{\"id\":37,\"position\":{\"x\":3.211819238806907,\"y\":0.8361365252640024,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-1.5207963275941434},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.6892099939523402,\"w\":0.72456164971396}},{\"id\":37,\"position\":{\"x\":2.1239044442716355,\"y\":0.7270494947133531,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":1.809203666420212},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.7861791507359865,\"w\":0.6179986593416227}},{\"id\":64,\"position\":{\"x\":1.2854428247993726,\"y\":2.1088075631936727,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-1.5707963267948963},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.7071067811865475,\"w\":0.7071067811865477}},{\"id\":160,\"position\":{\"x\":2.5180308423769353,\"y\":1.7037948087943773,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.0007963267961379878},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.00039816338754858187,\"w\":0.9999999207329553}},{\"id\":110,\"position\":{\"x\":4.363383838660308,\"y\":1.8446611590397413,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.6207963216517365},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.30543779417332834,\"w\":0.9522120320026057}},{\"id\":150,\"position\":{\"x\":0.38423754919784114,\"y\":2.8821267664956207,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.12920367633817348},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.06455691268644366,\"w\":0.9979140268702484}},{\"id\":179,\"position\":{\"x\":1.6566218773145178,\"y\":0.6982262358268683,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":-0.3207963322474933},\"quaternion\":{\"x\":0,\"y\":0,\"z\":-0.15971127443568203,\"w\":0.9871637700088726}},{\"id\":116,\"position\":{\"x\":0.7876551977953973,\"y\":1.0447069865075296,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.4692036732051035},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.2324557474516606,\"w\":0.9726069737960394}},{\"id\":123,\"position\":{\"x\":0.2772290873919028,\"y\":0.450067813046513,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0.9792036732051036},\"quaternion\":{\"x\":0,\"y\":0,\"z\":0.47027453822665294,\"w\":0.8825201746678136}}]\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10013';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "room_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(188,188)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10014';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "label_ids": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(36,36)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10015';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "displayorder": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10016';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "model_ids": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"157,37,37,64,160,110,150,179,116,123\",\"157,37,37,64,160,110,150,179,116,123\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10017';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "style": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\u73b0\u4ee3\",\"\u73b0\u4ee3\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10018';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "updator": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10019';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "advert_text": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10020';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "brand_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1,1)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10021';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "pic_resids": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10022';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "brand": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"Carlhansen&son\",\"Carlhansen&son\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10023';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "owner_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10024';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "category": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\u5c55\u5385\",\"\u5c55\u5385\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10025';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "advert_author": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10026';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "create_time": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1431681119,1431681119)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10027';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "adv_top": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10028';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "scene_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(267,267)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10029';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "remark": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(\"\",\"\")";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10030';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "isfav": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10031';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "category_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(19,19)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10032';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "area": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(12,12)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10033';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "update_time": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(1431920552,1431920552)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10034';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            },
            "pics": {},
            "from_id": function() {
                var window = function() {
                    return this;
                } ();
                function geneVal(key) {
                    var o = __rap__context__[key];
                    var arr = o.arr;
                    return arr[o.index++%arr.length];
                }
                if (!window.__rap__context__) {
                    window.__rap__context__ = {};
                }
                var orderCmd = "$order(0,0)";
                var orderArr = eval('[' + orderCmd.substring(7, orderCmd.length - 1) + ']');
                var key = '10035';
                if (!__rap__context__[key]) {
                    __rap__context__[key] = {
                        arr: orderArr,
                        index: 0
                    };
                }
                return geneVal(key);
            }
        }]
    }
    
    opened by Bosn 4
  • mock没有阻止ajax请求

    mock没有阻止ajax请求

    预览地址 : mock-demo

        <script>
            Mock.mock('mockjs.json', {
                'list|1-10':[{
                    'id|+1':1,
                    'email':'@EMAIL'
                }]
            });
    
            $.ajax({
                url: 'mockjs.json',
            }).done(function(data, status, xhr){
                console.dir(
                    JSON.stringify(data, null, 4)
                )
            })
        </script>
    

    mock没有阻止ajax请求,报错!请问这是为啥?

    opened by ghostcode 4
  • 返回固定的数据 数据里包含 @符号的时候会报错

    返回固定的数据 数据里包含 @符号的时候会报错

    
    module.exports = [
      {
        path: '/nested',
        component: 'Layout',
        redirect: '/nested/menu1',
        name: 'Nested',
        meta: {
          title: 'Nested',
          icon: 'nested',
          roles: ['admin', 'editor']
        },
        children: [
          {
            path: 'menu1',
            component: '@/views/nested/menu1/index', // Parent router-view
            name: 'Menu1',
            meta: {
              title: 'Menu1',
              roles: ['admin', 'editor']
            },
            children: [
              {
                path: 'menu1-1',
                component: '@/views/nested/menu1/menu1-1',
                name: 'Menu1-1',
                meta: {
                  title: 'Menu1-1',
                  roles: ['admin', 'editor']
                }
              },
              {
                path: 'menu1-2',
                component: '@/views/nested/menu1/menu1-2',
                name: 'Menu1-2',
                meta: {
                  title: 'Menu1-2',
                  roles: ['admin', 'editor']
                },
                children: [
                  {
                    path: 'menu1-2-1',
                    component: '@/views/nested/menu1/menu1-2/menu1-2-1',
                    name: 'Menu1-2-1',
                    meta: {
                      title: 'Menu1-2-1',
                      roles: ['admin', 'editor']
                    }
                  },
                  {
                    path: 'menu1-2-2',
                    component: '@/views/nested/menu1/menu1-2/menu1-2-2',
                    name: 'Menu1-2-2',
                    meta: { title: 'Menu1-2-2' }
                  }
                ]
              },
              {
                path: 'menu1-3',
                component: '@/views/nested/menu1/menu1-3',
                name: 'Menu1-3',
                meta: { title: 'Menu1-3' }
              }
            ]
          },
          {
            path: 'menu2',
            component: '@/views/nested/menu2/index',
            meta: { title: 'menu2' }
          }
        ]
      }
    ]
    
    
    
    opened by shen-lan 3
  • 简单的array

    简单的array

    我想要单纯的array,如下:  [ "Mock.js", "Mock.js", "Mock.js", "Mock.js", "Mock.js", "Mock.js" ] 但是例子中Mock.mock({ "array|1-10": [ "Mock.js" ] })会得到 { [ "Mock.js", "Mock.js", "Mock.js", "Mock.js", "Mock.js", "Mock.js" ] },外面多了{},要如何正确使用??

    opened by deded007 3
  • 能否让mock规则支持运算?

    能否让mock规则支持运算?

    1、能否让mock规则支持运算? 可以实现简单的加减乘除,这样就可以配合动态参数,模拟出比较真实地接口行为。

    2、能否获取当前数组元素的index?比如用@INDEX来表示 虽然可以通过增加一个自增类型的字段来辅助实现(例如自增id,可以用@id来获取index),不过该辅助字段并非接口真实所用的字段。

    opened by miclay 3
  • req.header 有值吗?

    req.header 有值吗?

        req.header 有值吗?
    

    Originally posted by @wll8 in https://github.com/nuysoft/Mock/issues/499#issuecomment-1352772113 req没有header这个值,所以无法通过req.header为undefined

    opened by zhangsandegea 1
  • bug: 重写了upload属性为空对象{},导致业务中使用到xhr.upload. addEventListener时报错

    bug: 重写了upload属性为空对象{},导致业务中使用到xhr.upload. addEventListener时报错

    https://github.com/nuysoft/Mock/blob/00ce04b92eb464e664a4438430903f2de96efb47/src/mock/xhr/xhr.js#L258

    XMLHttpRequest.upload https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/upload

    opened by Eric124120 0
Releases(1.0.1-beta3)
Owner
高云 墨智
《jQuery 技术内幕》作者
高云 墨智
ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript

mori A simple bridge to ClojureScript's persistent data structures and supporting APIs for vanilla JavaScript. Pull requests welcome. Breaking changes

David Nolen 3.4k Dec 31, 2022
A complete, fully tested and documented data structure library written in pure JavaScript.

Buckets A JavaScript Data Structure Library Buckets is a complete, fully tested and documented data structure library written in pure JavaScript. Incl

Mauricio 1.2k Jan 4, 2023
Immutable persistent data collections for Javascript which increase efficiency and simplicity.

Immutable collections for JavaScript Immutable data cannot be changed once created, leading to much simpler application development, no defensive copy

Immutable.js 32.4k Jan 7, 2023
mutate a copy of data without changing the original source

immutability-helper Mutate a copy of data without changing the original source Setup via NPM npm install immutability-helper --save This is a drop-in

Moshe Kolodny 5.1k Dec 29, 2022
JSON-Schema + fake data generators

Use JSON Schema along with fake generators to provide consistent and meaningful fake data for your system. What's next? Breaking-changes towards v0.5.

JSON Schema Faker 2.9k Jan 4, 2023
🛠️construct-js is a library for creating byte level data structures.

??️construct-js is a library for creating byte level data structures.

Francis Stokes 1.3k Dec 14, 2022
Contains html file showcasing Earthquake related data generated in the form of VR model, ArcGIS API with real-time earthquake feed and video of simulation of earthquake generated in blender

Module-EADGI-Project-All about Earthquakes Introduction Contains html file showcasing Earthquake related data generated in the form of VR model, ArcGI

Abhishek Rawat 2 Jun 9, 2022
A lightweight IDE that supports verilog simulation and Risc-V code compilation

EveIDE_LIGHT 使用手册 当前版本 : v0.0.2-beta (支持windows7以上版本 64位操作系统) 作者 : Adancurusul 版本说明 版本部分特性 概述 什么是EveIDE_LIGHT 使用介绍 选择工作区 进入主界面 左侧模组区 工程视图 编译设置 仿真设置 右侧

Chen Yuheng 43 Aug 29, 2022
A simulation of ant foraging with pheromones.

Ant Simulation A simulation of ant foraging with pheromones. Live Demo Sources & Credits Coding Adventure: Ant and Slime Simulations by Sebastian Lagu

PlebusSupremus1234 3 Oct 2, 2021
Nouns On-Chain Proposal Simulation and Analysis

Nouns Diligence Nouns On-Chain Proposal Simulation and Analysis For Voters Technical reports for all reviewed proposals can be found in the reports fo

Nouns 23 Dec 26, 2022
A Pauli Test simulation app made with Web Component and RxJS

There was a discussion quite a while ago in Teknologi Umum about brain throughput or something. Basically it was about how long does your brain can maintain its performance. It was brought up because there was a discussion about typing speed and how someone can get high Words per Minute at the start but starts to slow down the longer they go.

elianiva 5 Jun 8, 2022
A large scale simulation which pits millions of space ships against each other in a virtual universe all running directly in SingleStore.

Wasm Space Program In this demo we simulate a fake universe full of thousands of solar systems. In each solar system there are many space ships and en

SingleStore Labs 11 Nov 2, 2022
🐜 GPU-accelerated ant colony simulation

Ants simulation A simple ant colony GPU-accelerated simulation made with Three.js. Live demo Rules Ants can emit two types of pheromones: to-home pher

null 10 Nov 28, 2022
Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

is a handy plugin for Obsidian that helps you generate text content using the powerful language model GP

null 356 Dec 29, 2022
a babel plugin that can transform generator function to state machine, which is a ported version of typescript generator transform

Babel Plugin Lite Regenerator intro This babel plugin is a ported version of TypeScript generator transform. It can transform async and generator func

Shi Meng 6 Jul 8, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.

Redash is designed to enable anyone, regardless of the level of technical sophistication, to harness the power of data big and small. SQL users levera

Redash 22.4k Dec 30, 2022
JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

Aykut Saraç 20.6k Jan 4, 2023
It shows an effective way to correct bus arrival information using data analytics based on Amazon Serverless such as Kiness Data Stream, Kinesis Data Firehose, S3, and Lambda.

Amazon Serverless를 이용한 실시간 버스 정보 수집 및 저장 본 github repository는 버스 정보를 주기적으로 수집하여 분석할 수 있도록, Amazon Serverless인 Amazon Kinesis Data Stream, Kinesis Data

John Park 4 Nov 13, 2022
A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

Mantine DataTable A "dark-theme aware" table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagina

Ionut-Cristian Florescu 331 Jan 4, 2023