1.在index.html同级文件夹下新建config.js:
window.global_config = {
BASE_URL: "http://baidu.com", //服务地址,可打包后动态修改
};
2.在index.html加入:
<script src="./config.js"></script>
3.在封装的公共请求如request.js里加入:
service.interceptors.request.use(config => {
config.url = window.global_config.BASE_URL+config.url;
})