File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = [ {
2
+ "_id" : "540000198212061166" ,
3
+ "username" : "冯霞" ,
4
+ "age" : 28
5
+ } , {
6
+ "_id" : "360000198410117032" ,
7
+ "username" : "张静" ,
8
+ "age" : 28
9
+ } , {
10
+ "_id" : "510000198812169757" ,
11
+ "username" : "唐霞" ,
12
+ "age" : 23
13
+ } , {
14
+ "_id" : "540000201002128195" ,
15
+ "username" : "陆平" ,
16
+ "age" : 24
17
+ } , {
18
+ "_id" : "990000200708037438" ,
19
+ "username" : "乔涛" ,
20
+ "age" : 23
21
+ } ]
Original file line number Diff line number Diff line change
1
+ const Mock = require ( 'mockjs' )
2
+ const fs = require ( 'fs' )
3
+
4
+ const {
5
+ users
6
+ } = Mock . mock ( {
7
+ "users|5" : [ {
8
+ "_id" : "@id()" ,
9
+ "username" : "@cname()" ,
10
+ "age|20-30" : 30
11
+ } ]
12
+ } )
13
+
14
+ const res = 'module.exports = ' + JSON . stringify ( users )
15
+ // 新建文件,写入数据
16
+ fs . writeFile ( './user-data.js' , res , function ( error ) {
17
+ if ( error ) {
18
+ console . log ( '写入失败' )
19
+ } else {
20
+ console . log ( '写入成功了' )
21
+ }
22
+ } )
You can’t perform that action at this time.
0 commit comments