本文共 995 字,大约阅读时间需要 3 分钟。
npm install mockjs
import "@/utils/mock";
let Mock = require('mockjs');// 例1Mock.mock('/api-infos/user/get-info', function () { return Mock.mock({ success: true, msg: '', obj: { "account_name": "@name", "gender|1": ["male", "female"], "birthday": Mock.Random.datetime('yyyy-MM-dd'), "address": "a b c d" } })});// 例2Mock.mock('/api-infos/user/message', function (req) { let pgSize = JSON.parse(req.body).pgSize; let res = { success: true, msg: '', obj: [] } for (let i = 0; i < pgSize; i++) { res.obj.push(Mock.mock({ "subject|2-10": "aaaaa", "id|1-100": 100, "time": Mock.Random.datetime('yyyy-MM-dd HH:mm'), "type|1": ['order', 'system'], "tip": '您有一条新的提货消息,速来提取>>', "status|1": ['seen', 'unseen'] })) } return res;});
配置完成之后, 就可以正常使用了
请求接口就是 mock 中自己设置的接口转载地址:http://qiukx.baihongyu.com/