Skip to content

Commit 49e7b6c

Browse files
committed
add mock data
1 parent 62198cf commit 49e7b6c

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

build/dev-server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require('./check-versions')()
22
var config = require('../config')
33
if (!process.env.NODE_ENV) process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
44
var path = require('path')
5+
var fs = require('fs')
56
var express = require('express')
67
var webpack = require('webpack')
78
var opn = require('opn')
@@ -44,6 +45,13 @@ Object.keys(proxyTable).forEach(function (context) {
4445
app.use(proxyMiddleware(context, options))
4546
})
4647

48+
// mock data
49+
var mockDir = path.resolve(__dirname, '../mock')
50+
fs.readdirSync(mockDir).forEach(function (file) {
51+
var mock = require(path.resolve(mockDir, file))
52+
app.use(mock.api, mock.response)
53+
})
54+
4755
// handle fallback for HTML5 history API
4856
app.use(require('connect-history-api-fallback')())
4957

config/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ module.exports = {
2222
assetsSubDirectory: 'static',
2323
assetsPublicPath: '/',
2424
proxyTable: {
25-
// '/edu_rest/**': {
26-
// target: 'http://www/api',
27-
// changeOrigin: true
28-
// }
25+
'/edu_rest/**': {
26+
target: 'http://other.domain/api',
27+
changeOrigin: true
28+
}
2929
},
3030
// CSS Sourcemaps off by default because relative paths are "buggy"
3131
// with this option, according to the CSS-Loader README

mock/get_regions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const faker = require('faker')
2+
faker.locale = 'zh_CN'
3+
4+
module.exports = {
5+
api: '/mock/edu_rest/acquire_campus/:id',
6+
response: function (req, res) {
7+
res.json({
8+
rlt: 'true',
9+
msg: 'ok',
10+
data: [
11+
{ id: faker.random.uuid(), name: faker.random.words() },
12+
{ id: faker.random.uuid(), name: faker.random.words() },
13+
{ id: faker.random.uuid(), name: faker.random.words() }
14+
]
15+
})
16+
}
17+
}

mock/login.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const faker = require('faker')
2+
3+
module.exports = {
4+
api: '/mock/edu_rest/org_login',
5+
response: function (req, res) {
6+
res.json({
7+
rlt: 'true',
8+
msg: 'ok',
9+
data: faker.random.uuid()
10+
})
11+
}
12+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "vue-project-demo",
2+
"name": "vue-spa-project",
33
"version": "1.0.0",
4-
"description": "教务系统 Demo",
4+
"description": "基于Vue.js技术栈的教务管理系统 Demo",
55
"author": "super_xp@126.com",
66
"private": true,
77
"scripts": {
@@ -56,6 +56,7 @@
5656
"eventsource-polyfill": "^0.9.6",
5757
"express": "^4.14.0",
5858
"extract-text-webpack-plugin": "^1.0.1",
59+
"faker": "^4.0.0",
5960
"file-loader": "^0.9.0",
6061
"friendly-errors-webpack-plugin": "^1.1.2",
6162
"function-bind": "^1.1.0",

src/services/API.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* 接口配置
33
*/
44

5-
// const BaseUrl = 'http://www/api'
6-
const BaseUrl = '' // for local proxy
5+
// const BaseUrl = 'http://www/api' // for production
6+
// const BaseUrl = '' // for local poxy
7+
const BaseUrl = '/mock' // for local mock test
78

89
export const LOGIN = BaseUrl + '/edu_rest/org_login' // 登录
910
export const REGIST = BaseUrl + '/edu_rest/org_register' // 注册

0 commit comments

Comments
 (0)