*The maka engine provides a 'fetch' object for implementing the mock mechanism. The followings is an example:*
*action.js*
```javascript
import {fetch} from 'maka'
...
fetch.post('/v1/login',{user: 'admin', password: '123'})
...
```
*mock.js*
```javascript
import { fetch } from 'maka'
const mockData = fetch.mockData
function initMockData() {
if (!mockData.users) {
mockData.users = [{
id: 1,
account: 13334445556,
password: 'c4ca4238a0b923820dcc509a6f75849b',
name: 'zlj'
}]
}
}
fetch.mock('/v1/login', (option, headers) => {
initMockData()
const user = mockData.users.find(o => o.account == option.account && o.password == option.password)
if (user) {
return {
result: true,
token: `${user.id},${user.account},${user.password},${user.name ? user.name : ''}`,
value: option
}
}
else {
return { result: false, error: { message: 'Please enter the correct username and password.(default user:13334445556,password:1)' } }
}
})
```
*index.js*
```javascript
import 'mock.js'
```
*index.html*
```javascript
window.main = function (maka) {
maka.utils.fetch.config({
mock: true
})
}
```
- Introduction
- What is maka?
- Installation
- Getting Started
- Command Line Tool
- Main concepts
- State
- Action
- View
- Advanced concepts
- Expression
- View reserved keywords
- Custom components
- Custom template components
- ActionMixin
- App && Hub
- App
- Hub
- Maka API
- Maka Api
- Ajax && Mock
- Ajax
- Mock
- Navigate
- navigate
- Team
- Our Team
- Done