-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
3,988 additions
and
3,640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Button } from 'antd'; | ||
import Mock from 'mockjs'; | ||
import { useState } from 'react'; | ||
|
||
const options = { | ||
'str1|2': 'a', | ||
'str2|1-5': 'a', | ||
'num1|+1': 1, | ||
'num2|1-10': 1, | ||
'num3|1-10.2': 1, | ||
'boolean|1': true, | ||
'obj1|1-3': { | ||
'310005': '重庆市', | ||
'310000': '上海市', | ||
'320000': '江苏省', | ||
'330000': '浙江省', | ||
'340000': '安徽省', | ||
}, | ||
'arr1|1': ['11', '22', '33'], | ||
'arr2|2': ['11'], | ||
'arr3|1-5': ['11'], | ||
'@guid': '@guid', | ||
'@id': '@id', | ||
'@name': '@name', | ||
'@cfirst': '@cfirst', | ||
'@clast': '@clast', | ||
'@cname': '@cname', | ||
'@ctitle': '@ctitle', | ||
'@cparagraph': '@cparagraph(2)', | ||
'@csentence': '@csentence', | ||
'@email': '@email(163.com)', | ||
'@url': '@url(https)', | ||
'@ip': '@ip', | ||
'@zip': '@zip', | ||
'@date': '@date', | ||
'@time': '@time', | ||
'@datetime': '@datetime', | ||
'@color': '@color', | ||
'@rgb': '@rgb', | ||
'@rgba': '@rgba', | ||
'@phone': '@phone', | ||
'@region': '@region', | ||
'@county': '@county(true)', | ||
'@province@city@county': '@province@city@county', | ||
}; | ||
|
||
const defaultData = Mock.mock(options); | ||
|
||
const Demo1 = () => { | ||
const [obj, setObj] = useState(defaultData); | ||
|
||
return ( | ||
<div> | ||
<Button | ||
type="primary" | ||
onClick={() => { | ||
setObj(Mock.mock(options)); | ||
}} | ||
> | ||
刷新 | ||
</Button> | ||
<pre style={{ background: '#f5f5dc', fontSize: 16, fontWeight: 700 }}> | ||
{JSON.stringify(obj, null, 4)} | ||
</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Demo1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: better-mock | ||
toc: content | ||
nav: | ||
--- | ||
|
||
# Mock 数据 | ||
|
||
一般我们会使用`Mock.js`库, 这里更推荐 `better-mock`库 [better-mock](https://github.com/lavyun/better-mock) | ||
|
||
- 100% 兼容 Mock.js。 | ||
- 使用 typescript 进行重构,更好的代码提示。 | ||
- 更加现代化的构建打包方案。 | ||
- 更加完善的单元测试。 | ||
- 支持对 fetch 的拦截。 | ||
- 支持主流小程序(微信、支付宝、头条、百度)。 | ||
|
||
如果想调用接口进行网络请求推荐使用 `mockm`库 [mockm](https://github.com/wll8/mockm) | ||
|
||
Mock.js 更多示例代码 [Mock.js 更多示例代码](http://mockjs.com/examples.html#Image) | ||
|
||
## 代码演示 | ||
|
||
### 基础用法 | ||
|
||
<code src='./demos/Demo1.tsx' background="#f5f5f5"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.