1. Create config.js in the static static directory, as shown in the figure
config.js
const globalData = {
localBaseUrl: 'https://www.xxxx.com/service/api', // 现测试地址
corpId:'ding562e6256565rw56r323t3ff3fgghhh2351' //公司的钉钉id
}
2. Set "template" under h5 of manifest.json: "template.h5.html"
3. Create a new template.h5.html file in the root directory of the project, and import the configuration file config.js into this file
template.h5.html file content, import configuration file 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>
4. Re-run the uniapp project, be sure to restart it after configuration
5. How to use
Just use it where you need it
const serviceIP = globalData.localBaseUrl;//接口配置
The configuration method of vue can be viewed in this article written before