Skip to content

Commit

Permalink
Rename default request prefix property name
Browse files Browse the repository at this point in the history
  • Loading branch information
lampo1024 committed Feb 16, 2019
1 parent 32d761e commit 29c924d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DncZeus.App/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const getUserInfo = (token) => {
url: 'account/profile',
method: 'get',
//是否在请求资源中添加资源的前缀
withPrefix: false, //设置为true或者不设置此属性,将默认添加配置文件config.baseUrl.prefix的前缀,如果设置下面这个属性[prefix],默认配置文件中的默认前缀将不可用
withPrefix: false, //设置为true或者不设置此属性,将默认添加配置文件config.baseUrl.defaultPrefix的前缀,如果设置下面这个属性[prefix],默认配置文件中的默认前缀将不生效
//请求资源的前缀重写
prefix:"api/v1/" //设此属性权重最高,将覆盖配置文件[baseUrl.prefix]中的前缀,withPrefix对此属性不起作用(也就是说只要设置了此属性,都将在请求中添加设置的前缀)
prefix:"api/v1/" //设此属性权重最高,将覆盖配置文件[baseUrl.defaultPrefix]中的前缀,withPrefix对此属性不起作用(也就是说只要设置了此属性,都将在请求中添加设置的前缀)
})
}

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.App/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
baseUrl: {
dev: 'http://localhost:54321/',
pro: 'http://localhost:54321/',
prefix:"api/v1/"
defaultPrefix:"api/v1/"
},
authUrl: {
dev: 'http://localhost:54321/api/oauth/auth',
Expand Down
4 changes: 2 additions & 2 deletions DncZeus.App/src/libs/api.request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HttpRequest from '@/libs/axios'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro
const prefix = config.baseUrl.prefix;
const axios = new HttpRequest(baseUrl,prefix)
const defaultPrefix = config.baseUrl.defaultPrefix;
const axios = new HttpRequest(baseUrl,defaultPrefix)
export default axios
6 changes: 3 additions & 3 deletions DncZeus.App/src/libs/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const addErrorLog = errorInfo => {
}

class HttpRequest {
constructor(baseUrl = baseURL, prefix) {
constructor(baseUrl = baseURL, defaultPrefix= defaultPrefix) {
this.baseUrl = baseUrl
this.prefix = prefix
this.defaultPrefix = defaultPrefix
this.queue = {}
}
getInsideConfig() {
Expand Down Expand Up @@ -146,7 +146,7 @@ class HttpRequest {
url = options.prefix + options.url
}
else if (withPrefix) {
url = this.prefix + options.url
url = this.defaultPrefix + options.url
}
options.url = url
options = Object.assign(this.getInsideConfig(), options)
Expand Down

0 comments on commit 29c924d

Please sign in to comment.