vue配置请求本地json数据需要哪些步骤

2025-01-24 08:26:16
推荐回答(1个)
回答1:

在const app = express()后,const compiler = webpack(webpackConfig)前配置即可,
var appData = require('../data.json')
var seller = appData.seller
var goods = appData.goods
var ratings = appData.ratings
var foods = appData.foods
var pice = appData.pice
var apiRoutes = express.Router()

apiRoutes.post('/foods', function (req, res) {
res.json({
errno: 0,
data: foods
});
})

apiRoutes.get('/seller', function (req, res) {
res.json({
errno: 0,
data: seller
});
})

apiRoutes.get('/goods', function (req, res) {
res.json({
errno: 0,
data: goods
})
})

apiRoutes.get('/ratings', function (req, res) {
res.json({
errno: 0,
data: ratings
});
})

apiRoutes.get('/pice', function (req, res) {
res.json({
errno: 0,
data: pice
});
})
app.use('/api',apiRoutes)