1.在根目录下创建.env.alpha的文件,文件内容如下
NODE_ENV = 'production'
VUE_APP_NAME = 'alpha'
2.打开package.json文件,在scripts对象中加上
"alpha": "vue-cli-service build --mode alpha"
3.在baseUrl(当前是baseUrl.js)配置页面写上
export let baseUrl = '';
if (process.env.NODE_ENV == 'production') {
if (process.env.VUE_APP_NAME == 'build') {
baseUrl = ''; //执行npm run build时的baseUrl值
} else {
baseUrl = ''; //执行npm run alpha时的baseUrl值
}
} else {
baseUrl = ''; //开发环境的baseUrl值
}
4.在请求中使用baseUrl
import * as httpHelper from './httpHelper'
import { baseUrl } from './baseUrl'
export function api_getExamQuestion(params) {
return httpHelper.get(baseUrl + '/api/peopleExam/listSubject', params);
}