1 安装mock
npm install mock webpack-api-mocker --save-dev
2 配置webpack
webpack.dev.config.js
const apiMocker = require('webpack-api-mocker');
modle.export = {
...
plugins:[
...
new webpack.DefinePlugin({
MOCK: true
})
],
devServer: {
...
before(app){
apiMocker(app, path.resolve(__dirname, '/Mock/index.js'))
}
}
}
3 使用
Mock/index.js
module.exports = {
[`GET /StuHologram/Fail/tabOne/First`]: (req, res) => {
return {
... // data
};
}
}