const express = require(‘express’)
const app = express();
var appData = require(‘../data.json’)
var seller = appData.seller
var goods = appData.goods
var ratings = appData.ratings
var apiRoutes = express.Router()
app.use(‘/api’, apiRoutes)
//第二步找到devServer,在里面添加
devServer: {
before(app) {
app.get(‘/api/seller’, (req, res, next) => {
res.json(seller)
}),
app.get(‘/api/goods’, (req, res) => {
res.json({
errno: 0,
data: goods
})
}),
app.get(‘/api/ratings’, (req, res) => {
res.json({
errno: 0,
data: ratings
})
})
},
clientLogLevel: ‘warning’,
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, ‘index.html’) },
],
},
都写后 重新 npm run dev 了 没报错 但是访问http://localhost:8080/#/api/seller 的时候 没有获取导数据 请问这是怎么回事 根目录下的data.json 也没问题啊。求解!!!