找到build文件下的webpack.dev.conf.js做如下修改:
在const portfinder = require('portfinder')下方加入如下语句:
const express = require('express')
const app = express()
const apiRouters = express.Router()
const appData = require('../data.json')
const seller = appData.seller
const goods = appData.goods
const ratings = appData.ratings
app.use('/api',apiRouters);
在devServer中加入如下语句:
before(app){
app.get('/api/seller',function(req,res){
res.json({
errno:0,
data:seller
})
}),
app.get('/api/goods',function(req,res){
res.json({
errno:0,
data:goods
})
}),
app.get('/api/ratings',function(req,res){
res.json({
errno:0,
data:ratings
})
})
},