json-server 在vue实例 webpack.prod.conf.js 配置
Ps:每次更新db.json 需要重新 npm run dev. 只能get 获取数据,不能使用post获取。
1.获取json-server
npm install json-server --save
2. 引入json-server
const jsonServer = require('json-server')
3.配置json-Server
1 const apiServer = jsonServer.create() // 创建服务 2 const apiRouter = jsonServer.router('db.json') // json数据 3 const middlewares = jsonServer.defaults() 4 apiServer.use(middlewares) 5 apiServer.use('/api', apiRouter)
4.监听8081端口
apiServer.listen(8081, function() { console.log('json Server is running') })
5.代理到8080端口(在config下的index.js)dve对象里添加



浙公网安备 33010602011771号