本地应用config.json
只须要把config.json文件放在static或webpack3生成的脚手架public里
应用config.json文件时,dev或serve开发环境能够运行和应用,生产环境会报跨域谬误。
{
"BASE_URL":"www.baidu.com"
}
应用(main.js里):
import "../public/config.json"
//webpack3/4
import "../static/config.json"
生产环境
因为无奈应用json了,换一种思路
在方才config.json的中央新建config.js
const config = {
path: "www.baidu.com", //接口地址
};
console.log(config);
sessionStorage.setItem('response', JSON.stringify(config));
console.log(JSON.parse(sessionStorage.getItem("response")).path)
应用(主入口文件index.html)
<script src="./config.js"></script>
在须要的中央
const path = JSON.parse(sessionStorage.getItem("response")).path
发表回复