vue 打包后动态配置API地址
1.static文件夹下新建config.js文件;
export const API = { // 测试环境 DEV_SERVER: 'http://20.21.1.112:9602', // 线上环境 PRO_SERVER: 'http://20.21.1.112:9602' }
2.引入依赖:cross-env;
"build": "cross-env NODE_ENV=production node build/build.js"
3.axios封装文件中引入config.js,根据环境判断使用接口地址;
import { API } from '../../static/js/config' let baseUrl = '' if (process.env.NODE_ENV =='development') { // 开发环境的url baseUrl = API.DEV_SERVER } else if (process.env.NODE_ENV == 'production') { // 正式环境的 request url baseUrl = API.PRO_SERVER } axios.defaults.baseURL = baseUrl
相关推荐
Luckyunyun 2020-08-15
染血白衣 2020-11-16
SAMXIE 2020-11-04
一个智障 2020-11-15
学习web前端 2020-11-09
yiranpiaoluo 2020-11-04
lxhuang 2020-11-03
88274956 2020-11-03
82387067 2020-11-03
huangliuyu00 2020-10-29
sichenglain 2020-10-27
Dayer 2020-10-27
小马的学习笔记 2020-10-23
liuweiITlove 2020-10-14
kjyiyi 2020-10-10
fanjunjaden 2020-10-09
zhyue 2020-09-28
huangliuyu00 2020-09-24