1 安裝koa, koa-router
npm install koa
npm install koa-routervue
2 新建mock文件夾,新建server.js 和 testData.jsgit
server.js
const Koa = require('koa')
const app = new Koa()
var Router = require('koa-router')
var router = new Router()
var testData = require('./testData.js')
router.get('/test', (ctx) => {
ctx.body = testData
})
app.use(router.routes())
.use(router.allowedMethods())
app.listen(5000)
複製代碼
testData.js
module.exports = [
{
title: '數據模擬'
}
]複製代碼
3 在package.json 中加入啓動命令npm
4 訪問 http://localhost:5000/testjson
5 代碼參考 https://git.coding.net/sunqun/vue-demo.gitbash