09485e79 by 406803045

修改全局变量VUE_APP_ENV

1 parent a65a25d7
1 NODE_ENV 1 NODE_ENV='development'
2 # just a flag 2 # must start with VUE_APP_
3 ENV = 'development' 3 VUE_APP_ENV = 'development'
4 #base url 4 #base url
5 BASE_URL = https://www.xxx.com/ 5 BASE_URL = 'https://www.xxx.com/'
6 # base api 6 # base api
7 VUE_APP_BASE_API = '/dev-api' 7 VUE_APP_BASE_API = '/dev-api'
8 VUE_CLI_BABEL_TRANSPILE_MODULES = true 8 VUE_CLI_BABEL_TRANSPILE_MODULES = true
......
1 # just a flag 1 NODE_ENV='production'
2 ENV = 'production' 2 # must start with VUE_APP_
3 VUE_APP_ENV = 'production'
3 #base url 4 #base url
4 BASE_URL = https://www.top1buyer.com/ 5 BASE_URL = https://www.top1buyer.com/
5 # base api 6 # base api
......
1 NODE_ENV = production 1 NODE_ENV='production'
2 2 # must start with VUE_APP_
3 # just a flag 3 VUE_APP_ENV = 'staging'
4 ENV = 'staging' 4 #base url
5 #base url 5 #base url
6 BASE_URL = https://www.top1buyer.com/ 6 BASE_URL = https://www.top1buyer.com/
7 # base api 7 # base api
......
...@@ -3,6 +3,7 @@ import request from '@/utils/request' ...@@ -3,6 +3,7 @@ import request from '@/utils/request'
3 import { api } from '@/config' 3 import { api } from '@/config'
4 // api 4 // api
5 const { common_api } = api 5 const { common_api } = api
6
6 // 登录 7 // 登录
7 export function login(params) { 8 export function login(params) {
8 return request({ 9 return request({
......
1 // 根据环境引入不同配置 process.env.NODE_ENV 1 // 根据环境引入不同配置 process.env.NODE_ENV
2 const config = require('./env.' + process.env.ENV) 2 const config = require('./env.' + process.env.VUE_APP_ENV)
3 console.log( process.env.ENV)
4 module.exports = config 3 module.exports = config
......
1 import axios from 'axios'
2 import store from '@/store'
3
4 // create an axios instance
5 const service = axios.create({
6 baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
7 withCredentials: true, // send cookies when cross-domain requests
8 timeout: 5000 // request timeout
9 })
10
11 // request interceptor
12 service.interceptors.request.use(
13 config => {
14 // do something before request is sent
15 if (store.getters.token) {
16 // let each request carry token
17 // ['X-Token'] is a custom headers key
18 // please modify it according to the actual situation
19 config.headers['X-Token'] = ''
20 }
21 return config
22 },
23 error => {
24 // do something with request error
25 console.log(error) // for debug
26 return Promise.reject(error)
27 }
28 )
29
30 // response interceptor
31 service.interceptors.response.use(
32 response => {
33 const res = response.data
34
35 // if the custom code is not 20000, it is judged as an error.
36 if (res.code !== 20000) {
37 Message({
38 message: res.message || 'error',
39 type: 'error',
40 duration: 5 * 1000
41 })
42
43 // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
44 if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
45 // to re-login
46 MessageBox.confirm(
47 'You have been logged out, you can cancel to stay on this page, or log in again',
48 'Confirm logout',
49 {
50 confirmButtonText: 'Re-Login',
51 cancelButtonText: 'Cancel',
52 type: 'warning'
53 }
54 ).then(() => {
55 store.dispatch('user/resetToken').then(() => {
56 location.reload()
57 })
58 })
59 }
60 return Promise.reject(res.message || 'error')
61 } else {
62 return res
63 }
64 },
65 error => {
66 console.log('err' + error) // for debug
67 Message({
68 message: error.message,
69 type: 'error',
70 duration: 5 * 1000
71 })
72 return Promise.reject(error)
73 }
74 )
75
76 export default service
1 import axios from 'axios' 1 import axios from 'axios'
2 import store from '@/store' 2 import store from '@/store'
3 import { Toast } from 'vant' 3 import { Toast } from 'vant'
4 import { api } from '@/config'
4 // create an axios instance 5 // create an axios instance
5 const service = axios.create({ 6 const service = axios.create({
6 baseURL: process.env.BASE_URL, // url = base url + request url 7 baseURL: api.base_api, // url = base url + request url
7 withCredentials: true, // send cookies when cross-domain requests 8 withCredentials: true, // send cookies when cross-domain requests
8 timeout: 5000 // request timeout 9 timeout: 5000 // request timeout
9 }) 10 })
......
...@@ -7,30 +7,32 @@ ...@@ -7,30 +7,32 @@
7 </template> 7 </template>
8 8
9 <script> 9 <script>
10 import { 10 // import { api } from '@/config'
11 Button 11 import {
12 } from 'vant' 12 Button
13 export default { 13 } from 'vant'
14 components: { 14 export default {
15 'van-button': Button 15 components: {
16 }, 16 'van-button': Button
17 },
17 18
18 data() { 19 data () {
19 return {} 20 return {}
20 }, 21 },
21 22
22 computed: {}, 23 computed: {},
23 24
24 mounted() {}, 25 mounted () {
26 console.log(process.env)
27 },
25 28
26 methods: {} 29 methods: {}
27 } 30 }
28 31
29 </script> 32 </script>
30 <style lang='scss' scoped> 33 <style lang='scss' scoped>
31 h1 { 34 h1 {
32 background: red; 35 background: red;
33 width: 375px; 36 width: 375px;
34 } 37 }
35
36 </style> 38 </style>
......
1 'use strict' 1 'use strict'
2 const path = require('path') 2 const path = require('path')
3 const defaultSettings = require('./src/config/index.js') 3 const defaultSettings = require('./src/config/index.js')
4 function resolve(dir) { 4 function resolve(dir) {
5 return path.join(__dirname, dir) 5 return path.join(__dirname, dir)
6 } 6 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!