在开发中碰到一个问题,若是公共配置写在src里面会被打包,没法作到可读性能够随时更改配置,因此只能写在static文件夹下,那么就实现一个公共配置文件吧。javascript
const httpUrl = 'http://190.168.1.1:18003/api' function errorMethod(error, obj) { console.log(error) if (typeof (error.response) === 'undefined') { obj.$message({ message: '网络异常,请稍后再试...', type: 'error' }) return } if (error.response.status === 403) { obj.$router.push('/') } else { obj.$message({ message: '网络异常,请稍后再试...', type: 'error' }) } } export default { httpUrl, errorMethod }
import config from '../static/config' vue.prototype.config1 = config
资源搜索网站大全 https://www.renrenfan.com.cn 广州VI设计公司https://www.houdianzi.comphp
this.config1.httpUrl
然鹅。。。上面的这种操做并无卵用,只是文件不打包,可是实际上仍是打包进去了,不管怎么改外面这个包都无效。css
既然import引用都会将文件打包,那么就采用非import方式引用,也就是最原始的引入js文件方式。html
一、在static文件夹下建立文件common.jsvue
var common = {
httpUrl: 'http://192.168.1.1:18003/project', pollTime: 10000, errorMethod: function(error, obj) { console.log(error) if (typeof (error.response) === 'undefined') { obj.$message({ message: '网络异常,请稍后再试...', type: 'error' }) return } if (error.response.status === 403) { obj.$router.push('/') } else { obj.$message({ message: '网络异常,请稍后再试...', type: 'error' }) } } }
二、在你的vue-cli根目录的index.html文件中添加你的这个js文件引用。java
<script src="static/common.js"></script>
三、就按照这种引入方式来调用便可拿到值。vue-cli
common.httpUrl