fix: fixed mock server (#541)

This commit is contained in:
花裤衩 2020-01-09 20:53:06 +08:00 committed by GitHub
parent 227ca9b649
commit 95c7bf5d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 21 deletions

View File

@ -53,9 +53,10 @@ export function mockXHR() {
// for mock server // for mock server
const responseFake = (url, type, respond) => { const responseFake = (url, type, respond) => {
return { return {
url: new RegExp(`/mock${url}`), url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
type: type || 'get', type: type || 'get',
response(req, res) { response(req, res) {
console.log('request invoke:' + req.path)
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond)) res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
} }
} }

View File

@ -13,7 +13,7 @@ const data = Mock.mock({
export default [ export default [
{ {
url: '/table/list', url: '/vue-admin-template/table/list',
type: 'get', type: 'get',
response: config => { response: config => {
const items = data.items const items = data.items

View File

@ -26,7 +26,7 @@ const users = {
export default [ export default [
// user login // user login
{ {
url: '/user/login', url: '/vue-admin-template/user/login',
type: 'post', type: 'post',
response: config => { response: config => {
const { username } = config.body const { username } = config.body
@ -49,7 +49,7 @@ export default [
// get user info // get user info
{ {
url: '/user/info\.*', url: '/vue-admin-template/user/info\.*',
type: 'get', type: 'get',
response: config => { response: config => {
const { token } = config.query const { token } = config.query
@ -72,7 +72,7 @@ export default [
// user logout // user logout
{ {
url: '/user/logout', url: '/vue-admin-template/user/logout',
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function getList(params) { export function getList(params) {
return request({ return request({
url: '/table/list', url: '/vue-admin-template/table/list',
method: 'get', method: 'get',
params params
}) })

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function login(data) { export function login(data) {
return request({ return request({
url: '/user/login', url: '/vue-admin-template/user/login',
method: 'post', method: 'post',
data data
}) })
@ -10,7 +10,7 @@ export function login(data) {
export function getInfo(token) { export function getInfo(token) {
return request({ return request({
url: '/user/info', url: '/vue-admin-template/user/info',
method: 'get', method: 'get',
params: { token } params: { token }
}) })
@ -18,7 +18,7 @@ export function getInfo(token) {
export function logout() { export function logout() {
return request({ return request({
url: '/user/logout', url: '/vue-admin-template/user/logout',
method: 'post' method: 'post'
}) })
} }

View File

@ -36,18 +36,7 @@ module.exports = {
warnings: false, warnings: false,
errors: true errors: true
}, },
proxy: { before: require('./mock/mock-server.js')
// change xxx-api/login => mock/login
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:${port}/mock`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
after: require('./mock/mock-server.js')
}, },
configureWebpack: { configureWebpack: {
// provide the app's title in webpack's name field, so that // provide the app's title in webpack's name field, so that