1.手动切换
export const BASE_URL = 'http://codercba.com:9002'
// export const BASE_URL = 'http://codercba.prod:9002'
export const TIME_OUT = 10000
2.依赖当前环境: development/production
console.log(process.env.NODE_ENV)
let BASE_URL = ''
if (process.env.NODE_ENV === 'development') {
BASE_URL = 'http://codercba.dev:9002'
} else {
BASE_URL = 'http://codercba.prod:9002'
}
export { BASE_URL }
3.从定义的环境变量的配置文件中, 加载变量
- 根目录下新建开发环境的文件和生产环境的文件,dev.env.js 和 prod.env.js
console.log(process.env.REACT_APP_BASE_URL)
标签:Vue,http,URL,codercba,环境,React,BASE,export,env
From: https://www.cnblogs.com/DL-CODER/p/17084240.html