Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
xqz
/
dianDemo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
09485e79
authored
2019-05-27 16:51:41 +0800
by
406803045
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改全局变量VUE_APP_ENV
1 parent
a65a25d7
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
98 deletions
.env.development
.env.production
.env.staging
src/api/user.js
src/config/index.js
src/utils/request.1.js
src/utils/request.js
src/views/home/index.vue
vue.config.js
.env.development
View file @
09485e7
NODE_ENV
#
just a flag
ENV = 'development'
NODE_ENV
='development'
#
must start with VUE_APP_
VUE_APP_
ENV = 'development'
#base url
BASE_URL =
https://www.xxx.com/
BASE_URL =
'https://www.xxx.com/'
# base api
VUE_APP_BASE_API = '/dev-api'
VUE_CLI_BABEL_TRANSPILE_MODULES = true
...
...
.env.production
View file @
09485e7
# just a flag
ENV = 'production'
NODE_ENV='production'
# must start with VUE_APP_
VUE_APP_ENV = 'production'
#base url
BASE_URL = https://www.top1buyer.com/
# base api
...
...
.env.staging
View file @
09485e7
NODE_ENV
= production
# just a flag
ENV = 'staging'
NODE_ENV
='production'
# must start with VUE_APP_
VUE_APP_ENV = 'staging'
#base url
#base url
BASE_URL = https://www.top1buyer.com/
# base api
...
...
src/api/user.js
View file @
09485e7
...
...
@@ -3,6 +3,7 @@ import request from '@/utils/request'
import
{
api
}
from
'@/config'
// api
const
{
common_api
}
=
api
// 登录
export
function
login
(
params
)
{
return
request
({
...
...
src/config/index.js
View file @
09485e7
// 根据环境引入不同配置 process.env.NODE_ENV
const
config
=
require
(
'./env.'
+
process
.
env
.
ENV
)
console
.
log
(
process
.
env
.
ENV
)
const
config
=
require
(
'./env.'
+
process
.
env
.
VUE_APP_ENV
)
module
.
exports
=
config
...
...
src/utils/request.1.js
deleted
100644 → 0
View file @
a65a25d
import
axios
from
'axios'
import
store
from
'@/store'
// create an axios instance
const
service
=
axios
.
create
({
baseURL
:
process
.
env
.
VUE_APP_BASE_API
,
// url = base url + request url
withCredentials
:
true
,
// send cookies when cross-domain requests
timeout
:
5000
// request timeout
})
// request interceptor
service
.
interceptors
.
request
.
use
(
config
=>
{
// do something before request is sent
if
(
store
.
getters
.
token
)
{
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation
config
.
headers
[
'X-Token'
]
=
''
}
return
config
},
error
=>
{
// do something with request error
console
.
log
(
error
)
// for debug
return
Promise
.
reject
(
error
)
}
)
// response interceptor
service
.
interceptors
.
response
.
use
(
response
=>
{
const
res
=
response
.
data
// if the custom code is not 20000, it is judged as an error.
if
(
res
.
code
!==
20000
)
{
Message
({
message
:
res
.
message
||
'error'
,
type
:
'error'
,
duration
:
5
*
1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if
(
res
.
code
===
50008
||
res
.
code
===
50012
||
res
.
code
===
50014
)
{
// to re-login
MessageBox
.
confirm
(
'You have been logged out, you can cancel to stay on this page, or log in again'
,
'Confirm logout'
,
{
confirmButtonText
:
'Re-Login'
,
cancelButtonText
:
'Cancel'
,
type
:
'warning'
}
).
then
(()
=>
{
store
.
dispatch
(
'user/resetToken'
).
then
(()
=>
{
location
.
reload
()
})
})
}
return
Promise
.
reject
(
res
.
message
||
'error'
)
}
else
{
return
res
}
},
error
=>
{
console
.
log
(
'err'
+
error
)
// for debug
Message
({
message
:
error
.
message
,
type
:
'error'
,
duration
:
5
*
1000
})
return
Promise
.
reject
(
error
)
}
)
export
default
service
src/utils/request.js
View file @
09485e7
import
axios
from
'axios'
import
store
from
'@/store'
import
{
Toast
}
from
'vant'
import
{
api
}
from
'@/config'
// create an axios instance
const
service
=
axios
.
create
({
baseURL
:
process
.
env
.
BASE_URL
,
// url = base url + request url
baseURL
:
api
.
base_api
,
// url = base url + request url
withCredentials
:
true
,
// send cookies when cross-domain requests
timeout
:
5000
// request timeout
})
...
...
src/views/home/index.vue
View file @
09485e7
...
...
@@ -7,30 +7,32 @@
</
template
>
<
script
>
import
{
// import { api } from '@/config'
import
{
Button
}
from
'vant'
export
default
{
}
from
'vant'
export
default
{
components
:
{
'van-button'
:
Button
},
data
()
{
data
()
{
return
{}
},
computed
:
{},
mounted
()
{},
mounted
()
{
console
.
log
(
process
.
env
)
},
methods
:
{}
}
}
</
script
>
<
style
lang=
'scss'
scoped
>
h1
{
h1
{
background
:
red
;
width
:
375px
;
}
}
</
style
>
...
...
vue.config.js
View file @
09485e7
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment