diff --git a/packages/fes-plugin-request/src/template/genRequestKey.js b/packages/fes-plugin-request/src/template/genRequestKey.js index db36fb6c..12c843a7 100644 --- a/packages/fes-plugin-request/src/template/genRequestKey.js +++ b/packages/fes-plugin-request/src/template/genRequestKey.js @@ -5,11 +5,20 @@ import { isURLSearchParams } from './helpers'; * 一个请求同时包含 data | params 参数的设计本身不合理 * 不对这种情况进行兼容 */ -export default async function genRequestKey(ctx, next) { - const { url, data, method } = ctx.config; + +const getQueryString = (data) => { if (isURLSearchParams(data)) { - ctx.key = `${url}${data.toString()}${method}`; + return data.toString(); } - ctx.key = `${url}${JSON.stringify(data)}${method}`; + return data ? JSON.stringify(data) : ''; +}; + +export default async function genRequestKey(ctx, next) { + const { + url, data, params, method + } = ctx.config; + + ctx.key = `${url}${getQueryString(data)}${getQueryString(params)}${method}`; + await next(); } diff --git a/packages/fes-template-h5/src/pages/index.vue b/packages/fes-template-h5/src/pages/index.vue index 4ed55e6b..2ec56fc7 100644 --- a/packages/fes-template-h5/src/pages/index.vue +++ b/packages/fes-template-h5/src/pages/index.vue @@ -46,17 +46,37 @@ export default { // }).then((res) => { // console.log(res); // }); - request('/api', null, { - mergeRequest: true - }).then((res) => { - console.log(res); - }); - request('/api', null, { - throttle: 3000, - cache: true - }).then((res) => { - console.log(res); - }); + // request('/api', null, { + // mergeRequest: true + // }).then((res) => { + // console.log(res); + // }); + // request('/api', null, { + // throttle: 3000, + // cache: true + // }).then((res) => { + // console.log(res); + // }); + + const get = (id) => { + request('/get/api', { id }, { + method: 'get' + }); + }; + + const post = (id) => { + request('/get/api', { id }, { + }); + }; + + get(1); + get(2); + get(3); + + post(1); + post(2); + post(3); + // setTimeout(() => { // request('/api', null, {