mock.js用來模擬后端接口,源碼地址:https://github.com/nuysoft/Mock/wiki/Getting-Started
一、安裝mock.js
npm install mockjs --save
二、src路徑下創(chuàng)建mock文件夾

image.png
json文件夾用于存放json文件,與后端接口數(shù)據(jù)對(duì)應(yīng)
// mock.js 文件
import Mock from 'mockjs';
import firstURL from './json/firstURL.json';
Mock.mock('后端接口地址', () => {
// 返回json數(shù)據(jù)
return firstURL
})
// url地址使用正則匹配
Mock.mock(/prmsas\/deviceTemplate\/getByDeviceId/, () => {
return firstURL
})
三、main.js導(dǎo)入
import "@/src/mock/mock";