mock.js 官网
mock.js用来生成随机,拦截Ajax请求
创建mock.js的文件夹,在下级目录创建index.js
文件
import Mock from 'mockjs' // 导入mock
import { param2Obj } from '../src/utils' // 引入工具类
import user from './user' // 使用想要生成模拟数据的文件,并在统计目录创建
import table from './table'
import buildingsMessage from './buildingsMessage'
// 使用
const mocks = [
...user,
...table,
...buildingsMessage
]
// for front mock
// please use it cautiously, it will redefine XMLHttpRequest,
// which will cause many of your third-party libraries to be invalidated(like progress event).
export function mockXHR() {
// mock patch
// https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Mock.XHR.prototype.send = function() {
if (this.custom.xhr) {
this.custom.xhr.withCredentials = this.withCredentials || false