1.npm安装
npm install mockjs --save
2.创建mock和以下的文件
data.json:调用接口要返回的数据
3.在mockServer.js中引入文件和要拦截的接口地址
import Mock from 'mockjs'
import apiData from './data.json'
Mock.mock('/seller', { code: 0, data: apiData.seller })//data:要返回的数据
Mock.mock('/goods', { code: 0, data: apiData.goods })
Mock.mock('/ratings', { code: 0, data: apiData.ratings })
Mock.mock('/shop_info', { code: 0, data: apiData.info })
4.在main.js中引入即可
import "./mock/mockServer"
当然在用mock之前要先安装Ajax