一、在static靜態(tài)目錄下創(chuàng)建config.js,如圖
?config.js
const globalData = {
localBaseUrl: 'https://www.xxxx.com/service/api', // 現(xiàn)測試地址
corpId:'ding562e6256565rw56r323t3ff3fgghhh2351' //公司的釘釘id
}
二、在manifest.json 的h5下設(shè)置"template" : "template.h5.html"
?
三、在項目根目錄下新建 template.h5.html 文件,在該文件引入配置文件config.js
?template.h5.html 文件內(nèi)容,引入配置文件config.js
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<script src="./static/configjs/config.js"></script>
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
四、重新運行uniapp項目,配置后一定要重啟一下
五、使用方式
在需要的地方直接使用即可
const serviceIP = globalData.localBaseUrl;//接口配置
vue的配置方式可查看之前寫的這篇文章來源:http://www.zghlxwxcb.cn/news/detail-429831.html
vue項目打包后 希望可以修改配置(接口地址,系統(tǒng)名稱等)項目打包發(fā)布,之后可能存在接口域名更換,項目名稱修改等情況,就需要開發(fā)人員重新修改代碼,重新發(fā)布,比較費時費力。希望可以將這些配置在一個文件中,如需更換,運維可直接打開配置文件,更改保存即生效。......https://blog.csdn.net/QQ_Empire/article/details/126248877?spm=1001.2014.3001.5501文章來源地址http://www.zghlxwxcb.cn/news/detail-429831.html
到了這里,關(guān)于uniapp項目打包H5后 希望可以修改固定的配置(接口地址,系統(tǒng)名稱等)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!