修改全局变量VUE_APP_ENV

This commit is contained in:
406803045 2019-05-27 16:51:41 +08:00
parent a65a25d761
commit 09485e7952
9 changed files with 37 additions and 109 deletions

View File

@ -1,8 +1,8 @@
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

View File

@ -1,5 +1,6 @@
# 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

View File

@ -1,7 +1,7 @@
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

View File

@ -3,6 +3,7 @@ import request from '@/utils/request'
import { api } from '@/config'
// api
const { common_api } = api
// 登录
export function login(params) {
return request({

View File

@ -1,4 +1,3 @@
// 根据环境引入不同配置 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

View File

@ -1,76 +0,0 @@
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

View File

@ -1,9 +1,10 @@
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
})

View File

@ -7,30 +7,32 @@
</template>
<script>
import {
Button
} from 'vant'
export default {
components: {
'van-button': Button
},
// import { api } from '@/config'
import {
Button
} from 'vant'
export default {
components: {
'van-button': Button
},
data() {
return {}
},
data () {
return {}
},
computed: {},
computed: {},
mounted() {},
mounted () {
console.log(process.env)
},
methods: {}
}
methods: {}
}
</script>
<style lang='scss' scoped>
h1 {
background: red;
width: 375px;
}
h1 {
background: red;
width: 375px;
}
</style>

View File

@ -1,6 +1,6 @@
'use strict'
const path = require('path')
const defaultSettings = require('./src/config/index.js')
const defaultSettings = require('./src/config/index.js')
function resolve(dir) {
return path.join(__dirname, dir)
}