1.1.1 • Published 4 years ago
axios-mockjs-api v1.1.1
API
####import Api,{axios,mockjs,request,getExportObject,getPathFileApi} from "axios-mockjs-api"
const api = new Api({ getData:{ url: '/getCardAll', method: 'post', mockConfig: { employ: true, template: { 'list|30-100': [ { id: '@id', name: '@ctitle(3, 6)', title: '@ctitle(5,30)', content: '@cparagraph()', 'comments|1-50': 50, 'agreeWith|1-50': 50 } ], msg: '请求成功', code: 200 } } } });
//apikey.method employ: true -> mock api.getData.post().then(console.log) //{data: {…}, status: 200, statusText: 'OK', headers: {…}, config: {…}, …}
### getExportObject(modulesFiles, isDefault)
>####modulesFiles : require.context(directory,useSubdirectories,regExp)
>####isDefault = undefined : { defaultObject, exportObject }
>####isDefault = true : defaultObject
>####isDefault = false : exportObject
###getPathFileApi
```angular2html
|--apiAll
|--user.js
|--...js
user.js
export const login = {
url: '/login',
method: 'post',
mockConfig: {
employ: true,
template: {
token: '@id',
user: {
name: '@cname',
img: '@image(200x100,#50B347, #FFF,Mock.js)',
city: '@county(true)',
content: '@cparagraph()',
data: '@date("yyyy-MM-dd")'
},
msg: '请求成功',
'code|1': [200, 500]
}
}
};
import {getPathFileApi} from 'axios-mockjs-api';
const fileList = require.context('./apiAll', true, /\.js$/);
const fileApi = getPathFileApi(fileList, false)
//fileApi = {user: Api, ...}