1.在static目录下新建config.js文件
window.g = {
BASE_URL: "https://localhost:111"
}
在index.html文件中引入此js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- 引入配置文件-->
<script type=text/javascript src="/static/config.js"></script>
<title></title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
.vue文件中访问方法
axios.get(window.g.BASE_URL+'/api/Default/GetAllCustomerName?keyword='+query)
打包出来的文件目录

2.目录结构
打开build下的webpack.prod.conf.js,删掉所有[某某hash],如图我注释掉了,打包好后将生成app.js,app.css等
本文介绍如何在项目中设置全局环境变量,并使用Webpack进行高效打包。通过在static目录下创建config.js文件,定义BASE_URL,可在.vue文件中通过axios访问。调整webpack.prod.conf.js中的hash设置,可优化打包后的文件结构。
1033

被折叠的 条评论
为什么被折叠?



