From 58f1c9e8d8bc52ea71c6a03e18472fa401ad8ad8 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Thu, 08 Apr 2021 10:49:43 +0800 Subject: [PATCH] 再次优化请求策略 --- bases/Fetcher.js | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bases/Fetcher.js b/bases/Fetcher.js index b683b42..aae3313 100644 --- a/bases/Fetcher.js +++ b/bases/Fetcher.js @@ -18,7 +18,7 @@ this._data = { urlPrefix: options.urlPrefix || ['/api/common/', '/api/common/'], }; - if (project.host.mock) { + if (project.host.mock === 'on') { this._defaultConfig.url = Fetcher.host + project.host.assetsPath.replace('/assets', '/mocks'); } else { this._defaultConfig.url = Fetcher.host; @@ -50,8 +50,12 @@ spellURL(devSuffix, serSuffix) { let url = ''; // mock 模式 - if (project.host.mock) { + if (project.host.mock === 'on') { url = this._data.urlPrefix[0].replace('api/', '') + devSuffix + '.json'; + } + // 强制实际请求模式 + else if (project.host.mock === 'real') { + url = this._data.urlPrefix[1] + (serSuffix || devSuffix); } // 正常模式 else { @@ -99,7 +103,7 @@ * @return {Promise<any>} */ post(url, data, remap = [], options = null) { - if (project.host.mock) { + if (project.host.mock === 'on') { return this.get(url, data, remap = [], options); } const params = Qs.stringify(data); @@ -560,7 +564,7 @@ } // 非 http 协议打开时,使用设置的服务器地址 else if (project.host.server) { - return project.host.hosts[project.host.severType]; + return project.host.hosts[project.host.serverType]; } } } @@ -572,7 +576,7 @@ } // 生产 else { - return project.host.hosts[project.host.severType]; + return project.host.hosts[project.host.serverType]; } } })(); -- Gitblit v1.9.1