vue配置文件不打包

在開發中碰到一個問題,若是公共配置寫在src裏面會被打包,沒法作到可讀性能夠隨時更改配置,因此只能寫在static文件夾下,那麼就實現一個公共配置文件吧。javascript

 

在static文件夾下添加一個配置文件

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 }

 

在main.js文件中添加引用

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
相關文章
相關標籤/搜索