1. 程式人生 > >高仿餓了麽mock本地數據

高仿餓了麽mock本地數據

client row RR OS 返回 dev before spl false

新版webpack.dev.conf.js配置本地數據訪問:
// 引入express 模塊 const express = require(‘express‘) // 創建express對象 const app = express() // 引入請求文件 加載本地數據文件 const appData = require(‘../data.json‘) // 獲取對應的本地數據 const seller = appData.seller const goods = appData.goods const ratings = appData.ratings

devServer: {
    clientLogLevel: 
‘warning‘, historyApiFallback: { rewrites: [ { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, ‘index.html‘) }, ], }, hot: true, contentBase: false, // since we use CopyWebpackPlugin. compress: true, host: HOST || config.dev.host, port: PORT
|| config.dev.port, open: config.dev.autoOpenBrowser, overlay: config.dev.errorOverlay ? { warnings: false, errors: true } : false, publicPath: config.dev.assetsPublicPath, proxy: config.dev.proxyTable, quiet: true, // necessary for FriendlyErrorsPlugin watchOptions: { poll: config.dev.poll, }, before (app) {
// 創建不同的路由對象 配置接口 app.get(‘/api/seller‘, (req, res) => { res.json({ errno: 0, data: seller //接口返回json數據,上面配置的數據seller就賦值給data請求後調用 }) }) app.get(‘/api/goods‘, (req, res) => { res.json({ errno: 0, data: goods }) }) app.get(‘/api/ratings‘, (req, res) => { res.json({ errno: 0, data: ratings }) }) } },

在devServer中before方法中配置接口

高仿餓了麽mock本地數據