UNPKG

4.03 kBMarkdownView Raw
1<!-- ## Mock.js -->
2
3<h2 class="hide" href="#">Mock.js</h2>
4<img class="hide" src="mockjs.png" wid>
5
6<h1 style="color: #428BCA; margin-bottom: 30px;">
7 <i class="iconlogo" style="font-size: 80px;">&#x3435;</i>
8 <span>Mock.js</span>
9</h1>
10
11[![Build Status](https://api.travis-ci.org/nuysoft/Mock.png?branch=master)](http://travis-ci.org/nuysoft/Mock)
12<!-- [![GitHub version](https://badge.fury.io/gh/nuysoft%2FMock.png)](http://badge.fury.io/gh/nuysoft%2FMock) -->
13<!-- [![NPM version](https://badge.fury.io/js/mockjs.png)](http://badge.fury.io/js/mockjs) -->
14<!-- [![Bower version](https://badge.fury.io/bo/mockjs.png)](http://badge.fury.io/bo/mockjs) -->
15[![Views in the last 24 hours](https://sourcegraph.com/api/repos/github.com/nuysoft/Mock/counters/views-24h.png)](https://github.com/nuysoft/Mock/)
16
17Mock.js 是一款<!-- 有用且好用的 -->模拟数据生成器,旨在帮助前端攻城师独立于后端进行开发,帮助编写单元测试。提供了以下模拟功能:
18
19* 根据数据模板生成模拟数据
20* 模拟 Ajax 请求,生成并返回模拟数据
21* 基于 HTML 模板生成模拟数据
22
23## 在线编辑器
24<!-- 没有 Live Demo 的库都是耍流氓 -->
25
26* [数据模板编辑器](./editor.html#help)
27* [Handlebars &amp; Mustache](./demo/mock4tpl.html)
28* [KISSY XTemplate](./demo/mock4xtpl.html)
29
30## 下载
31
32<p>
33 <a href="./dist/mock.js" class="btn btn-success w250">
34 Development Version (0.1.4)
35 </a> - <i>71kB, Uncompressed</i>
36</p>
37<p>
38 <a href="./dist/mock-min.js" class="btn btn-primary w250">
39 Production Version (0.1.4)
40 </a> - <i>31kB, Minified</i>
41</p>
42<p>
43 <a href="https://github.com/nuysoft/Mock" class="btn btn-default w250">
44 从 Github 获取最新版本
45 </a> - <i>Unreleased</i>
46</p>
47
48<iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&repo=Mock&type=watch&count=true&size=large"
49 allowtransparency="true" frameborder="0" scrolling="0" width="131" height="30"></iframe>
50
51<iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&repo=Mock&type=fork&count=true&size=large"
52 allowtransparency="true" frameborder="0" scrolling="0" width="140" height="30"></iframe>
53
54<!-- <iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&type=follow&count=true&size=large"
55 allowtransparency="true" frameborder="0" scrolling="0" width="165" height="30"></iframe> -->
56
57## 分享文档
58
59* [懒懒交流会 2014.5.30](/doc/lanlan.html)
60
61## 用法
62
63### 浏览器
64
65<iframe width="100%" height="200" src="http://jsfiddle.net/DgJrj/embedded/html,js,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
66
67### Node (CommonJS)
68
69 // 安装
70 npm install mockjs
71
72 // 使用
73 var Mock = require('mockjs');
74 var data = Mock.mock({
75 'list|1-10': [{
76 'id|+1': 1
77 }]
78 });
79 console.log(JSON.stringify(data, null, 4))
80
81### Bower
82
83<!-- If you'd like to use [bower](http://bower.io/), it's as easy as: -->
84
85 npm install -g bower
86 bower install --save mockjs
87
88 <script type="text/javascript" src="./bower_components/mockjs/dist/mock.js"></script>
89
90
91### RequireJS (AMD)
92
93<iframe width="100%" height="350" src="http://jsfiddle.net/uTSqT/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
94
95### Sea.js (CMD)
96
97<iframe width="100%" height="350" src="http://jsfiddle.net/5jX6e/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
98
99### KISSY
100
101<iframe width="100%" height="400" src="http://jsfiddle.net/En2sX/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
102
103<!--
104Mock.js 已入驻 [KISSY Gallery](https://github.com/kissygalleryteam),阿里同学可以直接加载 `gallery/Mock/0.1.1/index`:
105
106<iframe width="100%" height="400" src="http://jsfiddle.net/8VNQQ/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
107-->
108
109### Random CLI
110
111 // 安装
112 npm install mockjs -g
113
114 // 执行
115 $ random url
116 // => http://rmcpx.org/funzwc
117
118---
\No newline at end of file