1:安装
cnpm install mockjs --save-dev
2:创建mock文件夹,创建mockjs
const Mock = require('mockjs');
const Random=Mock.Random;
const produceData=function(opt){
console.log('opt',opt);
let articles=[];
for(let i=0;i<30;i++){
let newArticleObject={
title:Random.csentence(5,30),
thumbnail_pic_s:Random.dataImage('300x250','mock的图片'),
author_name:Random.cname(),
date:Random.date(),
email:Random.email(),
name:Random.cname()
}
articles.push(newArticleObject)
}
return {
data:articles
}
}
Mock.mock('/one',/post|get/i,produceData);
3:在main.js中引入
import './mock/mock.js'