企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
*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 }) } ```