找到vue.config.js
项目根目录中存放模拟数据库,data.json
添加
const appData=require('./data.json')
const seller=appData.seller
const goods=appData.goods
const ratings=appData.ratings
在module.exports = {} 中添加代码
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
})
})
}
}
然后运行npm run serve
打开浏览器http://localhost:8080/api/seller
可以看到data.json中seller部分数据。