要求在打包好的文件中能够更改api请求前缀
在public/static中新建了一个config.js
![](https://img.haomeiwen.com/i8118696/4e22894355742d01.png)
![](https://img.haomeiwen.com/i8118696/d51a8bdb5ded10fe.png)
在public/index.html中引用config.js
![](https://img.haomeiwen.com/i8118696/603873954a8983a1.png)
![](https://img.haomeiwen.com/i8118696/325f0ffdc307ce36.png)
现在在项目中可以直接使用window.g.baseUrl、 window.g.imgUrl
放到vuex中使用更方便一点
![](https://img.haomeiwen.com/i8118696/7519fa3ead2347f9.png)
在view/页面中可以直接$store.state.api、$store.state.imgUrl来使用
mian.js中判断当前环境使用不同的接口前缀,开发环境下使用api代理
![](https://img.haomeiwen.com/i8118696/f4354e20311f1179.png)
打包后的文件中修改config.js就可以更改api前缀了
网友评论