mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
170 lines
63 KiB
HTML
170 lines
63 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<meta name="generator" content="VuePress 2.0.0-beta.53">
|
||
<style>
|
||
:root {
|
||
--c-bg: #fff;
|
||
}
|
||
html.dark {
|
||
--c-bg: #22272e;
|
||
}
|
||
html, body {
|
||
background-color: var(--c-bg);
|
||
}
|
||
</style>
|
||
<script>
|
||
const userMode = localStorage.getItem('vuepress-color-scheme');
|
||
const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||
if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
|
||
document.documentElement.classList.toggle('dark', true);
|
||
}
|
||
</script>
|
||
<link rel="manifest" href="/manifest.webmanifest"><link rel="icon" href="/logo.png"><title>@fesjs/plugin-request | Fes.js</title><meta name="description" content="一个好用的前端应用解决方案">
|
||
<link rel="preload" href="/fes.js/assets/style.2de37a47.css" as="style" /><link rel="stylesheet" href="/fes.js/assets/style.2de37a47.css" />
|
||
<link rel="modulepreload" href="/fes.js/assets/app.ae6ada9d.js"><link rel="modulepreload" href="/fes.js/assets/request.html.dc62f141.js"><link rel="modulepreload" href="/fes.js/assets/request.html.c75462cc.js"><link rel="prefetch" href="/fes.js/assets/index.html.422b4bf6.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.42b578aa.js" as="script" /><link rel="prefetch" href="/fes.js/assets/builder.html.d08bb011.js" as="script" /><link rel="prefetch" href="/fes.js/assets/config.html.381be2ea.js" as="script" /><link rel="prefetch" href="/fes.js/assets/contributing.html.c7916fbc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/css.html.a2eed2b5.js" as="script" /><link rel="prefetch" href="/fes.js/assets/directory-structure.html.f5c5db0a.js" as="script" /><link rel="prefetch" href="/fes.js/assets/env.html.988c2189.js" as="script" /><link rel="prefetch" href="/fes.js/assets/faq.html.4fafd53a.js" as="script" /><link rel="prefetch" href="/fes.js/assets/getting-started.html.7e1c58aa.js" as="script" /><link rel="prefetch" href="/fes.js/assets/image.html.c562b3bc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/mock.html.8b1b6d6c.js" as="script" /><link rel="prefetch" href="/fes.js/assets/plugin.html.bd21ddd8.js" as="script" /><link rel="prefetch" href="/fes.js/assets/public.html.fc8e758e.js" as="script" /><link rel="prefetch" href="/fes.js/assets/route.html.9f021449.js" as="script" /><link rel="prefetch" href="/fes.js/assets/runtime-config.html.63205e8e.js" as="script" /><link rel="prefetch" href="/fes.js/assets/template.html.57ff4996.js" as="script" /><link rel="prefetch" href="/fes.js/assets/upgrade3.html.ec734959.js" as="script" /><link rel="prefetch" href="/fes.js/assets/api.html.9434e329.js" as="script" /><link rel="prefetch" href="/fes.js/assets/cli.html.658bdf44.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.dd966b2d.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.76eb56e2.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.8e79357b.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.268a0441.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.65de0ef8.js" as="script" /><link rel="prefetch" href="/fes.js/assets/api.html.30af22c4.js" as="script" /><link rel="prefetch" href="/fes.js/assets/access.html.5effcdf7.js" as="script" /><link rel="prefetch" href="/fes.js/assets/editor.html.5719c3a8.js" as="script" /><link rel="prefetch" href="/fes.js/assets/enums.html.cd8fcafe.js" as="script" /><link rel="prefetch" href="/fes.js/assets/icon.html.b2743ab7.js" as="script" /><link rel="prefetch" href="/fes.js/assets/jest.html.9053deec.js" as="script" /><link rel="prefetch" href="/fes.js/assets/layout.html.a09688d9.js" as="script" /><link rel="prefetch" href="/fes.js/assets/locale.html.a78c1e3f.js" as="script" /><link rel="prefetch" href="/fes.js/assets/login.html.38e9b215.js" as="script" /><link rel="prefetch" href="/fes.js/assets/model.html.186b5cad.js" as="script" /><link rel="prefetch" href="/fes.js/assets/pinia.html.82f90437.js" as="script" /><link rel="prefetch" href="/fes.js/assets/qiankun.html.244ee6a6.js" as="script" /><link rel="prefetch" href="/fes.js/assets/sass.html.548ad0bc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/swc.html.d526d5ef.js" as="script" /><link rel="prefetch" href="/fes.js/assets/vuex.html.566cccfa.js" as="script" /><link rel="prefetch" href="/fes.js/assets/watermark.html.557ade0d.js" as="script" /><link rel="prefetch" href="/fes.js/assets/windicss.html.c9d632db.js" as="script" /><link rel="prefetch" href="/fes.js/assets/404.html.c3e557d0.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.c4d4026a.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.b0c940bc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/builder.html.dfadd983.js" as="script" /><link rel="prefetch" href="/fes.js/assets/config.html.f46c7cbb.js" as="script" /><link rel="prefetch" href="/fes.js/assets/contributing.html.19359b46.js" as="script" /><link rel="prefetch" href="/fes.js/assets/css.html.b5c698eb.js" as="script" /><link rel="prefetch" href="/fes.js/assets/directory-structure.html.dd9f0d3a.js" as="script" /><link rel="prefetch" href="/fes.js/assets/env.html.a957eb9b.js" as="script" /><link rel="prefetch" href="/fes.js/assets/faq.html.08deeff0.js" as="script" /><link rel="prefetch" href="/fes.js/assets/getting-started.html.0e1db8b2.js" as="script" /><link rel="prefetch" href="/fes.js/assets/image.html.65e30112.js" as="script" /><link rel="prefetch" href="/fes.js/assets/mock.html.79310110.js" as="script" /><link rel="prefetch" href="/fes.js/assets/plugin.html.7f62c62a.js" as="script" /><link rel="prefetch" href="/fes.js/assets/public.html.4b9aece3.js" as="script" /><link rel="prefetch" href="/fes.js/assets/route.html.a5a7fb50.js" as="script" /><link rel="prefetch" href="/fes.js/assets/runtime-config.html.95aca426.js" as="script" /><link rel="prefetch" href="/fes.js/assets/template.html.e79b2264.js" as="script" /><link rel="prefetch" href="/fes.js/assets/upgrade3.html.01af2d64.js" as="script" /><link rel="prefetch" href="/fes.js/assets/api.html.14cb2999.js" as="script" /><link rel="prefetch" href="/fes.js/assets/cli.html.5f3aeebb.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.eb2ceae3.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.11617833.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.87817e9b.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.ca2c838c.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.html.176671cc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/api.html.e5a082d4.js" as="script" /><link rel="prefetch" href="/fes.js/assets/access.html.d7746b65.js" as="script" /><link rel="prefetch" href="/fes.js/assets/editor.html.0971d1cc.js" as="script" /><link rel="prefetch" href="/fes.js/assets/enums.html.05c72dfd.js" as="script" /><link rel="prefetch" href="/fes.js/assets/icon.html.ba26904d.js" as="script" /><link rel="prefetch" href="/fes.js/assets/jest.html.24dd1913.js" as="script" /><link rel="prefetch" href="/fes.js/assets/layout.html.9a65bef5.js" as="script" /><link rel="prefetch" href="/fes.js/assets/locale.html.1a15b1af.js" as="script" /><link rel="prefetch" href="/fes.js/assets/login.html.9d0ca6a4.js" as="script" /><link rel="prefetch" href="/fes.js/assets/model.html.590fb5d3.js" as="script" /><link rel="prefetch" href="/fes.js/assets/pinia.html.04f1a6fa.js" as="script" /><link rel="prefetch" href="/fes.js/assets/qiankun.html.30407b9e.js" as="script" /><link rel="prefetch" href="/fes.js/assets/sass.html.b517feb8.js" as="script" /><link rel="prefetch" href="/fes.js/assets/swc.html.f5148656.js" as="script" /><link rel="prefetch" href="/fes.js/assets/vuex.html.95385d0c.js" as="script" /><link rel="prefetch" href="/fes.js/assets/watermark.html.3351d977.js" as="script" /><link rel="prefetch" href="/fes.js/assets/windicss.html.40ef52c0.js" as="script" /><link rel="prefetch" href="/fes.js/assets/404.html.1ed057aa.js" as="script" /><link rel="prefetch" href="/fes.js/assets/index.0b6f9a66.js" as="script" />
|
||
</head>
|
||
<body>
|
||
<div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/fes.js/" class=""><img class="logo" src="/fes.js/logo.png" alt="Fes.js"><span class="site-name can-hide">Fes.js</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><a href="/fes.js/guide/" class="" aria-label="指南"><!--[--><!--]--> 指南 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/config/" class="" aria-label="编译时配置"><!--[--><!--]--> 编译时配置 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/api/" class="" aria-label="API"><!--[--><!--]--> API <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/plugin/" class="router-link-active" aria-label="插件"><!--[--><!--]--> 插件 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/cli/" class="" aria-label="CLI"><!--[--><!--]--> CLI <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="v3.0.3"><span class="title">v3.0.3</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="v3.0.3"><span class="title">v3.0.3</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a class="external-link" href="https://fesjs.mumblefe.cn/2.0" rel="noopener noreferrer" target="_blank" aria-label="v2.0"><!--[--><!--]--> v2.0 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="https://fesjs.mumblefe.cn/1.0" rel="noopener noreferrer" target="_blank" aria-label="v1.0"><!--[--><!--]--> v1.0 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="了解更多"><span class="title">了解更多</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="了解更多"><span class="title">了解更多</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a class="external-link" href="https://github.com/WeBankFinTech/fes.js/blob/next/CHANGELOG.md" rel="noopener noreferrer" target="_blank" aria-label="更新日志"><!--[--><!--]--> 更新日志 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="http://fes-design.mumblefe.cn/" rel="noopener noreferrer" target="_blank" aria-label="fes-design"><!--[--><!--]--> fes-design <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a class="external-link" href="https://github.com/WeBankFinTech/fes.js" rel="noopener noreferrer" target="_blank" aria-label="GitHub"><!--[--><!--]--> GitHub <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><button class="toggle-color-mode-button" title="toggle color mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><div id="docsearch-container"></div></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-items"><!--[--><div class="navbar-item"><a href="/fes.js/guide/" class="" aria-label="指南"><!--[--><!--]--> 指南 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/config/" class="" aria-label="编译时配置"><!--[--><!--]--> 编译时配置 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/api/" class="" aria-label="API"><!--[--><!--]--> API <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/plugin/" class="router-link-active" aria-label="插件"><!--[--><!--]--> 插件 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/fes.js/reference/cli/" class="" aria-label="CLI"><!--[--><!--]--> CLI <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="v3.0.3"><span class="title">v3.0.3</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="v3.0.3"><span class="title">v3.0.3</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a class="external-link" href="https://fesjs.mumblefe.cn/2.0" rel="noopener noreferrer" target="_blank" aria-label="v2.0"><!--[--><!--]--> v2.0 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="https://fesjs.mumblefe.cn/1.0" rel="noopener noreferrer" target="_blank" aria-label="v1.0"><!--[--><!--]--> v1.0 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="了解更多"><span class="title">了解更多</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="了解更多"><span class="title">了解更多</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a class="external-link" href="https://github.com/WeBankFinTech/fes.js/blob/next/CHANGELOG.md" rel="noopener noreferrer" target="_blank" aria-label="更新日志"><!--[--><!--]--> 更新日志 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="http://fes-design.mumblefe.cn/" rel="noopener noreferrer" target="_blank" aria-label="fes-design"><!--[--><!--]--> fes-design <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a class="external-link" href="https://github.com/WeBankFinTech/fes.js" rel="noopener noreferrer" target="_blank" aria-label="GitHub"><!--[--><!--]--> GitHub <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-items"><!--[--><li><a href="/fes.js/reference/plugin/" class="router-link-active sidebar-item sidebar-heading" aria-label="介绍"><!--[--><!--]--> 介绍 <!--[--><!--]--></a><!----></li><li><p tabindex="0" class="sidebar-item sidebar-heading active">Plugins <!----></p><ul style="" class="sidebar-item-children"><!--[--><li><a href="/fes.js/reference/plugin/plugins/access.html" class="sidebar-item" aria-label="@fesjs/plugin-access"><!--[--><!--]--> @fesjs/plugin-access <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/enums.html" class="sidebar-item" aria-label="@fesjs/plugin-enums"><!--[--><!--]--> @fesjs/plugin-enums <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/icon.html" class="sidebar-item" aria-label="@fesjs/plugin-icon"><!--[--><!--]--> @fesjs/plugin-icon <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/jest.html" class="sidebar-item" aria-label="@fesjs/plugin-jest"><!--[--><!--]--> @fesjs/plugin-jest <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/layout.html" class="sidebar-item" aria-label="@fesjs/plugin-layout"><!--[--><!--]--> @fesjs/plugin-layout <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/locale.html" class="sidebar-item" aria-label="@fesjs/plugin-locale"><!--[--><!--]--> @fesjs/plugin-locale <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/model.html" class="sidebar-item" aria-label="@fesjs/plugin-model"><!--[--><!--]--> @fesjs/plugin-model <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html" class="router-link-active router-link-exact-active router-link-active sidebar-item active" aria-label="@fesjs/plugin-request"><!--[--><!--]--> @fesjs/plugin-request <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#启用方式" class="router-link-active router-link-exact-active sidebar-item" aria-label="启用方式"><!--[--><!--]--> 启用方式 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#运行时配置" class="router-link-active router-link-exact-active sidebar-item" aria-label="运行时配置"><!--[--><!--]--> 运行时配置 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#api" class="router-link-active router-link-exact-active sidebar-item" aria-label="API"><!--[--><!--]--> API <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#request" class="router-link-active router-link-exact-active sidebar-item" aria-label="request"><!--[--><!--]--> request <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#userequest" class="router-link-active router-link-exact-active sidebar-item" aria-label="useRequest"><!--[--><!--]--> useRequest <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#使用" class="router-link-active router-link-exact-active sidebar-item" aria-label="使用"><!--[--><!--]--> 使用 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#发起一个普通-post-请求" class="router-link-active router-link-exact-active sidebar-item" aria-label="发起一个普通 post 请求"><!--[--><!--]--> 发起一个普通 post 请求 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#merge-重复请求" class="router-link-active router-link-exact-active sidebar-item" aria-label="merge 重复请求"><!--[--><!--]--> merge 重复请求 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#请求缓存" class="router-link-active router-link-exact-active sidebar-item" aria-label="请求缓存"><!--[--><!--]--> 请求缓存 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#请求-abort" class="router-link-active router-link-exact-active sidebar-item" aria-label="请求 abort"><!--[--><!--]--> 请求 abort <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#获取-response-headers" class="router-link-active router-link-exact-active sidebar-item" aria-label="获取 response headers"><!--[--><!--]--> 获取 response headers <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#结合-use-使用" class="router-link-active router-link-exact-active sidebar-item" aria-label="结合 use 使用"><!--[--><!--]--> 结合 use 使用 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/fes.js/reference/plugin/plugins/request.html#_3-x-升级到-4-x" class="router-link-active router-link-exact-active sidebar-item" aria-label="3.x 升级到 4.x"><!--[--><!--]--> 3.x 升级到 4.x <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a href="/fes.js/reference/plugin/plugins/vuex.html" class="sidebar-item" aria-label="@fesjs/plugin-vuex"><!--[--><!--]--> @fesjs/plugin-vuex <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/qiankun.html" class="sidebar-item" aria-label="@fesjs/plugin-qiankun"><!--[--><!--]--> @fesjs/plugin-qiankun <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/windicss.html" class="sidebar-item" aria-label="@fesjs/plugin-windicss"><!--[--><!--]--> @fesjs/plugin-windicss <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/sass.html" class="sidebar-item" aria-label="@fesjs/plugin-sass"><!--[--><!--]--> @fesjs/plugin-sass <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/editor.html" class="sidebar-item" aria-label="@fesjs/plugin-monaco-editor"><!--[--><!--]--> @fesjs/plugin-monaco-editor <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/pinia.html" class="sidebar-item" aria-label="@fesjs/plugin-pinia"><!--[--><!--]--> @fesjs/plugin-pinia <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/watermark.html" class="sidebar-item" aria-label="@fesjs/plugin-watermark"><!--[--><!--]--> @fesjs/plugin-watermark <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/login.html" class="sidebar-item" aria-label="@fesjs/plugin-login"><!--[--><!--]--> @fesjs/plugin-login <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/plugins/swc.html" class="sidebar-item" aria-label="@fesjs/plugin-swc"><!--[--><!--]--> @fesjs/plugin-swc <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading">插件开发 <!----></p><ul style="" class="sidebar-item-children"><!--[--><li><a href="/fes.js/reference/plugin/dev/" class="sidebar-item" aria-label="插件介绍"><!--[--><!--]--> 插件介绍 <!--[--><!--]--></a><!----></li><li><a href="/fes.js/reference/plugin/dev/api.html" class="sidebar-item" aria-label="插件 API"><!--[--><!--]--> 插件 API <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><!--]--><div><h1 id="fesjs-plugin-request" tabindex="-1"><a class="header-anchor" href="#fesjs-plugin-request" aria-hidden="true">#</a> @fesjs/plugin-request</h1><p>基于 fetch 封装的 request,内置防止重复请求、请求缓存、错误处理等功能。</p><h2 id="启用方式" tabindex="-1"><a class="header-anchor" href="#启用方式" aria-hidden="true">#</a> 启用方式</h2><p>在 <code>package.json</code> 中引入依赖:</p><div class="language-json line-numbers-mode" data-ext="json"><pre class="language-json"><code><span class="token punctuation">{</span>
|
||
<span class="token property">"dependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||
<span class="token property">"@fesjs/fes"</span><span class="token operator">:</span> <span class="token string">"^3.0.0"</span><span class="token punctuation">,</span>
|
||
<span class="token property">"@fesjs/plugin-request"</span><span class="token operator">:</span> <span class="token string">"^4.0.0-beta.0"</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token punctuation">}</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="运行时配置" tabindex="-1"><a class="header-anchor" href="#运行时配置" aria-hidden="true">#</a> 运行时配置</h2><p>入口文件的全局配置,具体请求的配置参数会覆盖全局配置,支持 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#sending_a_request_with_credentials_included" target="_blank" rel="noopener noreferrer">fetch<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 所有的参数。</p><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> defineRuntimeConfig <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token function">defineRuntimeConfig</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
|
||
<span class="token literal-property property">request</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">baseURL</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
|
||
<span class="token literal-property property">timeout</span><span class="token operator">:</span> <span class="token number">10000</span><span class="token punctuation">,</span> <span class="token comment">// 默认 10s</span>
|
||
<span class="token literal-property property">method</span><span class="token operator">:</span> <span class="token string">'POST'</span><span class="token punctuation">,</span> <span class="token comment">// 默认 post</span>
|
||
<span class="token literal-property property">mergeRequest</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否合并请求</span>
|
||
<span class="token literal-property property">responseType</span><span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token comment">// 可选 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData',默认根据 content-type 处理</span>
|
||
<span class="token literal-property property">credentials</span><span class="token operator">:</span> <span class="token string">'include'</span><span class="token punctuation">,</span> <span class="token comment">// 默认 include, 'include' | 'same-origin' | 'omit'</span>
|
||
<span class="token literal-property property">headers</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">// 传给服务器的 header</span>
|
||
<span class="token literal-property property">cacheData</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 是否缓存</span>
|
||
<span class="token function-variable function">requestInterceptor</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token literal-property property">config</span><span class="token operator">:</span> Config</span><span class="token punctuation">)</span> <span class="token operator">=></span> Config<span class="token punctuation">,</span>
|
||
<span class="token function-variable function">responseInterceptor</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token literal-property property">response</span><span class="token operator">:</span> RequestResponse</span><span class="token punctuation">)</span> <span class="token operator">=></span> RequestResponse<span class="token punctuation">,</span>
|
||
<span class="token function">transformData</span><span class="token punctuation">(</span><span class="token parameter">data<span class="token punctuation">,</span> response</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 处理响应内容异常</span>
|
||
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">isPlainObject</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token keyword">if</span> <span class="token punctuation">(</span>data<span class="token punctuation">.</span>code <span class="token operator">===</span> <span class="token string">'10000'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token keyword">return</span> Promise<span class="token punctuation">.</span><span class="token function">reject</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token keyword">return</span> data<span class="token operator">?.</span>result <span class="token operator">?</span> data<span class="token punctuation">.</span>result <span class="token operator">:</span> data<span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token keyword">return</span> data<span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token comment">// http 异常,和插件异常</span>
|
||
<span class="token function">errorHandler</span><span class="token punctuation">(</span><span class="token parameter">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token keyword">if</span> <span class="token punctuation">(</span>error<span class="token punctuation">.</span>response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span>response<span class="token punctuation">.</span>data<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span>response<span class="token punctuation">.</span>status<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span>response<span class="token punctuation">.</span>headers<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>error<span class="token punctuation">.</span>msg<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span>msg<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 发送请求时出了点问题</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'Error'</span><span class="token punctuation">,</span> error<span class="token punctuation">.</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span>config<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token comment">// 支持其他 fetch 配置</span>
|
||
<span class="token operator">...</span>otherConfigs<span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="api" tabindex="-1"><a class="header-anchor" href="#api" aria-hidden="true">#</a> API</h2><h3 id="request" tabindex="-1"><a class="header-anchor" href="#request" aria-hidden="true">#</a> request</h3><ul><li><p><strong>类型</strong>:函数</p></li><li><p><strong>详情</strong>:请求后端接口</p></li><li><p><strong>参数</strong>:</p><ul><li>url: 后端接口 url</li><li>data: 参数</li><li>options: 配置支持 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#sending_a_request_with_credentials_included" target="_blank" rel="noopener noreferrer">fetch<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 所有的参数,和插件扩展参数。</li></ul></li><li><p><strong>返回值</strong>: Promise</p></li></ul><h3 id="userequest" tabindex="-1"><a class="header-anchor" href="#userequest" aria-hidden="true">#</a> useRequest</h3><p>request 的封装,返回响应式 <code>loading</code>、<code>error</code>、 <code>data</code></p><h2 id="使用" tabindex="-1"><a class="header-anchor" href="#使用" aria-hidden="true">#</a> 使用</h2><h3 id="发起一个普通-post-请求" tabindex="-1"><a class="header-anchor" href="#发起一个普通-post-请求" aria-hidden="true">#</a> 发起一个普通 post 请求</h3><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> request <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token function">request</span><span class="token punctuation">(</span><span class="token string">'/api/login'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">username</span><span class="token operator">:</span> <span class="token string">'robby'</span><span class="token punctuation">,</span>
|
||
<span class="token literal-property property">password</span><span class="token operator">:</span> <span class="token string">'123456'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// do something</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 处理异常</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="merge-重复请求" tabindex="-1"><a class="header-anchor" href="#merge-重复请求" aria-hidden="true">#</a> merge 重复请求</h3><p>连续发送多个请求,会被合并成一个请求,不会报 <code>REPEAT</code> 接口错误。</p><p>当发生 <code>REPEAT</code> 请求异常,并且确保自身代码合理的情况下,可以使用该配置。</p><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> request <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token function">request</span><span class="token punctuation">(</span>
|
||
<span class="token string">'/api/login'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token literal-property property">username</span><span class="token operator">:</span> <span class="token string">'robby'</span><span class="token punctuation">,</span>
|
||
<span class="token literal-property property">password</span><span class="token operator">:</span> <span class="token string">'123456'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token literal-property property">mergeRequest</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 在一个请求没有回来前,重复发送的请求会合并成一个请求</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// do something</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 处理异常</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="请求缓存" tabindex="-1"><a class="header-anchor" href="#请求缓存" aria-hidden="true">#</a> 请求缓存</h3><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> request <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token function">request</span><span class="token punctuation">(</span>
|
||
<span class="token string">'/api/login'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token literal-property property">username</span><span class="token operator">:</span> <span class="token string">'robby'</span><span class="token punctuation">,</span>
|
||
<span class="token literal-property property">password</span><span class="token operator">:</span> <span class="token string">'123456'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token literal-property property">cacheData</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">cacheType</span><span class="token operator">:</span> <span class="token string">'ram'</span><span class="token punctuation">,</span> <span class="token comment">// ram: 内存,session: sessionStorage,local:localStorage</span>
|
||
<span class="token literal-property property">cacheTime</span><span class="token operator">:</span> <span class="token number">1000</span> <span class="token operator">*</span> <span class="token number">60</span> <span class="token operator">*</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token comment">// 缓存时间:默认3min</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// do something</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||
<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">err</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
<span class="token comment">// 处理异常</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>若 <code>cacheData</code> 传 <code>true</code>,则默认使用 <code>ram</code> 缓存类型,缓存时间 3min。</p><h3 id="请求-abort" tabindex="-1"><a class="header-anchor" href="#请求-abort" aria-hidden="true">#</a> 请求 abort</h3><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> request <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">const</span> controller <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AbortController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token function">request</span><span class="token punctuation">(</span><span class="token string">'/url/abort'</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">signal</span><span class="token operator">:</span> controller<span class="token punctuation">.</span>signal<span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">response</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'process response: '</span> <span class="token operator">+</span> response<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token comment">// cancel the request</span>
|
||
controller<span class="token punctuation">.</span><span class="token function">abort</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="获取-response-headers" tabindex="-1"><a class="header-anchor" href="#获取-response-headers" aria-hidden="true">#</a> 获取 response headers</h3><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> rawRequest <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">const</span> controller <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AbortController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token function">rawRequest</span><span class="token punctuation">(</span><span class="token string">'/url/abort'</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">signal</span><span class="token operator">:</span> controller<span class="token punctuation">.</span>signal<span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">response</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'process headers: '</span> <span class="token operator">+</span> response<span class="token punctuation">.</span>headers<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token comment">// cancel the request</span>
|
||
controller<span class="token punctuation">.</span><span class="token function">abort</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="结合-use-使用" tabindex="-1"><a class="header-anchor" href="#结合-use-使用" aria-hidden="true">#</a> 结合 use 使用</h3><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> useRequest <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@fesjs/fes'</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
|
||
<span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||
<span class="token keyword">const</span> <span class="token punctuation">{</span> loading<span class="token punctuation">,</span> data<span class="token punctuation">,</span> error <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">useRequest</span><span class="token punctuation">(</span><span class="token string">'/api/login'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
|
||
<span class="token literal-property property">username</span><span class="token operator">:</span> <span class="token string">'robby'</span><span class="token punctuation">,</span>
|
||
<span class="token literal-property property">password</span><span class="token operator">:</span> <span class="token string">'123456'</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">return</span> <span class="token punctuation">{</span>
|
||
loading<span class="token punctuation">,</span>
|
||
data<span class="token punctuation">,</span>
|
||
error<span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="_3-x-升级到-4-x" tabindex="-1"><a class="header-anchor" href="#_3-x-升级到-4-x" aria-hidden="true">#</a> 3.x 升级到 4.x</h2><ol><li>缓存参数 cache 改成 cacheData(避免与 fetch 原本的 cache 冲突)</li><li>dataHandler 改成 transformData</li><li>requestInterceptors 改为 requestInterceptor,不在支持数组,只支持函数</li><li>responseInterceptors 改为 responseInterceptor,不在支持数组,只支持函数</li><li>其他 axios 特有的配置不在支持</li></ol></div><!--[--><!--]--></div><footer class="page-meta"><div class="meta-item edit-link"><a class="external-link meta-item-label" href="https://github.com/WeBankFinTech/fes.js/edit/next/docs/reference/plugin/plugins/request.md" rel="noopener noreferrer" target="_blank" aria-label="在 GitHub 上编辑此页"><!--[--><!--]--> 在 GitHub 上编辑此页 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></div><div class="meta-item last-updated"><span class="meta-item-label">上次更新: </span><!----></div><div class="meta-item contributors"><span class="meta-item-label">贡献者: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: 445436867@qq.com">wanchun</span><!----><!--]--><!--]--></span></div></footer><nav class="page-nav"><p class="inner"><span class="prev"><a href="/fes.js/reference/plugin/plugins/model.html" class="" aria-label="@fesjs/plugin-model"><!--[--><!--]--> @fesjs/plugin-model <!--[--><!--]--></a></span><span class="next"><a href="/fes.js/reference/plugin/plugins/vuex.html" class="" aria-label="@fesjs/plugin-vuex"><!--[--><!--]--> @fesjs/plugin-vuex <!--[--><!--]--></a></span></p></nav><!--[--><!--]--></main><!--]--></div><!----><!----><!--]--></div>
|
||
<script type="module" src="/fes.js/assets/app.ae6ada9d.js" defer></script>
|
||
</body>
|
||
</html>
|