问题描述
我把配置的内容放到了根目录下的一个config.js文件,然后在vue的入口index.html引入这个js文件
config.js代码如下:
window.g ={};
Object.assign(window.g, {
ApiUrl: 'http://127.0.0.1/tms-form/api/public/index.php',
domain : 'tmsformapi.wiltechs.com',
loginUrl : "http://tms.wiltechs.com"
});
Vue index.html的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>SJTMS FORM</title>
<script src="./config.js"></script>
</head>
<body>
<noscript>
你的浏览器版本过低,请更换你的浏览器
</noscript>
<div id="root"></div>
</body>
</html>
在子页面刷新会提提示变量不存在
从首页点击进去子页面的话能够正常访问变量,但是刷新页面的话,就不能读取变量了.如果在从首页重新进去的还是可以正常访问的
这个会不是和webpack的懒加载有关呢,欢迎探讨一下^_^