提示工程架构师入门:有效提示创作的5个常见问题,解答全在这里!
2026/1/16 21:33:23
用户输入的ip可以自动获取到 这样配置文件就不用写死了
proxy.base: `http://${location.hostname}`config
(function() { // 将配置信息放在window对象上,使其变成全局都可以访问的 window.config = { projectName: '1111', mapUrl: `http://${location.hostname}:8091/`, } })();使用window.config.projectNamewindow.config.mapUrl
apiConfig.js
// 全局配置对象 window.apiConfig = { // 代理基础路径 // proxyBase: 'http://17.2.3.201', proxyBase: `http://${location.hostname}`, // 各系统端口配置 systems: { system1: { name: '系统1', port: '8070' }, system2: { name: '系统2', port: '8071' }, system3: { name: '系统3', port: '11005' } }, getSystemUrl(systemKey) { if (!this.systems[systemKey]) { console.error(`未知的系统key: ${systemKey}`) return '' } return `${this.proxyBase}:${this.systems[systemKey].port}` } }使用的页面window.apiConfig.getSystemUrl(systemKey)
window.apiConfig.getSystemUrl(system1).name -- 系统1
window.apiConfig.getSystemUrl(system1).port -- 8087