<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: HcySunYang</title>
    <description>The latest articles on DEV Community by HcySunYang (@hcysunyang).</description>
    <link>https://dev.to/hcysunyang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F125715%2Fb5d4f332-9601-484a-8ace-f61b803a6b8b.jpeg</url>
      <title>DEV Community: HcySunYang</title>
      <link>https://dev.to/hcysunyang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hcysunyang"/>
    <language>en</language>
    <item>
      <title>Vapperjs - A Vue-based SSR framework</title>
      <dc:creator>HcySunYang</dc:creator>
      <pubDate>Mon, 04 Nov 2019 11:40:04 +0000</pubDate>
      <link>https://dev.to/hcysunyang/vapperjs-a-vue-based-ssr-framework-2e92</link>
      <guid>https://dev.to/hcysunyang/vapperjs-a-vue-based-ssr-framework-2e92</guid>
      <description>&lt;p&gt;If you are using &lt;code&gt;Vue&lt;/code&gt; to do isomorphic projects, then &lt;code&gt;Nuxt&lt;/code&gt; and the &lt;code&gt;Quasar Framework&lt;/code&gt; are good choices. But today I am going to introduce a new &lt;code&gt;SSR&lt;/code&gt; framework based on &lt;code&gt;Vue&lt;/code&gt;: &lt;a href="https://vapperjs.org/"&gt;https://vapperjs.org/&lt;/a&gt; .&lt;/p&gt;

&lt;h1&gt;
  
  
  The features of Vapper
&lt;/h1&gt;

&lt;p&gt;I guess most people will have a question after seeing the title of this article: Why not use a framework such as Nuxt or Quasar Framework directly, but instead create a wheel? Next, we will try to answer these questions by introducing the features of &lt;code&gt;Vapper&lt;/code&gt; to see what is different about &lt;code&gt;Vapper&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal 1: Vapper does its best to bring the development experience of SSR applications closer to SPA
&lt;/h2&gt;

&lt;p&gt;How can vapper do this? We need to consider in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Project structure:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We know that &lt;code&gt;Nuxt&lt;/code&gt; is a file system-based route, which means that it has a gap with the traditional &lt;code&gt;SPA&lt;/code&gt; application in how files are organized. You need to write pages (or components) according to their conventions. However, we don't have these limitations when developing &lt;code&gt;SPA&lt;/code&gt; applications, so we want a framework that allows us to organize files without any restrictions, just like the normal &lt;code&gt;SPA&lt;/code&gt; application.&lt;/p&gt;

&lt;p&gt;It's not that hard to achieve this, because the official documentation of Vue SSR teaches you this way, so &lt;code&gt;Vapper&lt;/code&gt; is just a wrapper on this basis.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2. Data prefetching:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have used &lt;code&gt;Nuxt&lt;/code&gt;, then you should be familiar with the &lt;code&gt;asyncData&lt;/code&gt; component option it provides. You need to do data prefetching in the &lt;code&gt;asyncData&lt;/code&gt; function, but it has some restrictions, such as the &lt;code&gt;asyncData&lt;/code&gt; component option can not be used for any component, and only Can be used in routing components(or &lt;code&gt;pages&lt;/code&gt;), and component instance are not accessible within the &lt;code&gt;asyncData&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Data prefetching, a simple understanding is request data, we do not have the limitation of "requesting data only in the routing component" when developing the &lt;code&gt;SPA&lt;/code&gt; application, and there is no need to worry about not being able to access the component instance. So we want a framework that will save you from these mental burdens and do its best to make data prefetching of isomorphic applications closer to the &lt;code&gt;SPA&lt;/code&gt; application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Vapper&lt;/code&gt; makes this all possible. For details, read the official documentation to learn how to prefetch data in &lt;code&gt;Vapper&lt;/code&gt;: &lt;a href="https://vapperjs.org/data-prefetching.html#data-prefetch"&gt;Data Prefetch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Through the above two efforts, we have almost made the experience of developing the &lt;code&gt;SSR&lt;/code&gt; application closer to the development of the &lt;code&gt;SPA&lt;/code&gt; application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal 2: Only responsible for the necessary webpack configuration
&lt;/h2&gt;

&lt;p&gt;Many companies or teams basically develop a so-called scaffolding tool, but most of the scaffolding tools developed by the team are only Vue CLI3 that implements 1% of the functions. In fact, under the existing architecture of Vue CLI3, you can fully implement the requirements of any business-specific scenario without having to write a scaffold yourself.&lt;/p&gt;

&lt;p&gt;Vue CLI3 draws on Poi's architectural ideas. Poi is also an excellent &lt;code&gt;webpack&lt;/code&gt; management tool, an excellent project scaffolding. So we hope to have such an SSR framework, which is only responsible for the necessary &lt;code&gt;webpack&lt;/code&gt; configuration, that is, only responsible for the SSR-related &lt;code&gt;webpack&lt;/code&gt; configuration, and other configurations are assigned to these excellent scaffolding management. The benefit of doing this is two-way, that is, &lt;code&gt;Vapper&lt;/code&gt; provides SSR capabilities for these scaffoldings, and the capabilities of these &lt;code&gt;webpack&lt;/code&gt; management tools have become &lt;code&gt;Vapper&lt;/code&gt;'s capabilities, two birds with one stone.&lt;/p&gt;

&lt;p&gt;One concept in Vapper is Configer, which is simply two modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/configer.html#vapper-configer-vue-cli"&gt;@vapper/configer-vue-cli&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/configer.html#vapper-configer-poi"&gt;@vapper/configer-poi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes it possible to combine Vapper with these great &lt;code&gt;webpack&lt;/code&gt; management tools, and more importantly, even if you don't use Vue CLI3 or Poi, you can write your own &lt;code&gt;Configer&lt;/code&gt; to integrate into your own scaffolding, the documentation can be read here: &lt;a href="https://vapperjs.org/configer.html#writing-configer"&gt;Write Configer&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal 3: Route level control
&lt;/h2&gt;

&lt;p&gt;What is the "route level control" capability? For the sake of understanding, I posted a picture of the official website:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jq6LsPBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vapperjs.org/assets/img/spa-ssr-prerender.701eb249.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jq6LsPBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vapperjs.org/assets/img/spa-ssr-prerender.701eb249.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a word, we hope that accessing different routes will be handled differently depending on the needs. For example, we want to apply server-side rendering(&lt;code&gt;SSR&lt;/code&gt;) when accessing route &lt;code&gt;/home&lt;/code&gt;; but send SPA resources to the user directly when accessing route &lt;code&gt;/foo&lt;/code&gt;; when accessing the route &lt;code&gt;/bar&lt;/code&gt;, we can send the pre-rendered content to the client.&lt;/p&gt;

&lt;p&gt;The reason for this is because sometimes, not all pages we need to do &lt;code&gt;SSR&lt;/code&gt;, and we can pre-render some of the pages, these are effective ways to improve service performance.&lt;/p&gt;

&lt;p&gt;You can do this easily in &lt;code&gt;Vapper&lt;/code&gt;. You can choose to turn &lt;code&gt;SSR&lt;/code&gt; on or off by specifying &lt;code&gt;ssr: true/false&lt;/code&gt; in the route &lt;code&gt;meta&lt;/code&gt;, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;VueRouter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;history&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Home.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Using SSR&lt;/span&gt;
        &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/About.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Turn off SSR, and send SPA resources when users access /foo&lt;/span&gt;
        &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's that simple and straightforward. At the same time, one thing I have to mention is that if all routes do not have &lt;code&gt;SSR&lt;/code&gt; applied, then your project is no different from the &lt;code&gt;SPA&lt;/code&gt; application. In other words, if you want to migrate an existing &lt;code&gt;SPA&lt;/code&gt; project to a &lt;code&gt;SSR&lt;/code&gt; project, then &lt;code&gt;Vapper&lt;/code&gt; is great for you.&lt;/p&gt;

&lt;p&gt;For pre-rendering to be a bit more complicated, you need to install the @vapper/plugin-prerender plugin and then configure it in &lt;code&gt;vapper.config.js&lt;/code&gt; as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vapper.config.js&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vapper/plugin-prerender&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// This is the route to be prerendered&lt;/span&gt;
        &lt;span class="na"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This way, during the build phase, &lt;code&gt;vapper&lt;/code&gt; will pre-render &lt;code&gt;/foo&lt;/code&gt; and generate a &lt;code&gt;html&lt;/code&gt; file, which will be sent directly to the client when the user accesses the route. It should be noted that pre-rendering is only supported for routes with SSR enabled, which is reasonable.&lt;/p&gt;

&lt;p&gt;Goal 4: Error handling&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Vapper&lt;/code&gt; makes the error handling more flexible, we have two choices when the error occurs:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xrtlfAHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vapperjs.org/assets/img/error-handling.3a08fb6c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xrtlfAHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vapperjs.org/assets/img/error-handling.3a08fb6c.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to displaying custom error pages, we can also choose to fall back to the SPA mode. The benefits of doing this are obvious, because some errors may only occur on the server, or some errors are non-fatal, we can choose to fall back to SPA mode when such error occurs, so that users can continue to use our application, which is very important for some scenarios that focus on conversion rates.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href="https://vapperjs.org/error-handling.html#error-handling"&gt;Error Handling&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  More features
&lt;/h2&gt;

&lt;p&gt;In addition to the core goals outlined above, &lt;code&gt;Vapper&lt;/code&gt; has other great features, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/caching.html#caching"&gt;Out-of-the-box micro-caching and Component level cache support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/injection.html#the-clientonly-component"&gt;The useful components, properties, and methods that Vapper injects for the application.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/custom-server.html#custom-server"&gt;Custom Connect/Express/Koa Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/write-plugin.html#basic"&gt;Vapper's plugin architecture and plugin development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vapperjs.org/using-plugin.html#basic-usage"&gt;Vapper's existing built-in plugin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have used &lt;code&gt;Vapper&lt;/code&gt; in our own projects, welcome &lt;code&gt;Star&lt;/code&gt;, &lt;code&gt;PR&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/shuidi-fed/vapper"&gt;Github: Vapper&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
    </item>
    <item>
      <title>Manage asynchronous calls more easily in Vue apps</title>
      <dc:creator>HcySunYang</dc:creator>
      <pubDate>Mon, 15 Jul 2019 15:15:43 +0000</pubDate>
      <link>https://dev.to/hcysunyang/manage-asynchronous-calls-more-easily-in-vue-apps-48f8</link>
      <guid>https://dev.to/hcysunyang/manage-asynchronous-calls-more-easily-in-vue-apps-48f8</guid>
      <description>&lt;p&gt;TOC:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What does an asynchronous call mean?&lt;/li&gt;
&lt;li&gt;Waiting for the loading of asynchronous components&lt;/li&gt;
&lt;li&gt;Use with vue-router&lt;/li&gt;
&lt;li&gt;How to display in the API request loading&lt;/li&gt;
&lt;li&gt;Use with vuex&lt;/li&gt;
&lt;li&gt;Capture all asynchronous calls in the component tree&lt;/li&gt;
&lt;li&gt;Resource manager&lt;/li&gt;
&lt;li&gt;Fork a resource manager&lt;/li&gt;
&lt;li&gt;Prevent option and prevent duplicate submissions&lt;/li&gt;
&lt;li&gt;Loading form&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;About LRU Cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/shuidi-fed/vue-async-manager" rel="noopener noreferrer"&gt;https://github.com/shuidi-fed/vue-async-manager&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Docs: &lt;a href="https://shuidi-fed.github.io/vue-async-manager/" rel="noopener noreferrer"&gt;https://shuidi-fed.github.io/vue-async-manager/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcaf6wpho6gslwhqttxi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcaf6wpho6gslwhqttxi.png" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Guide
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Manage asynchronous calls more easily in Vue apps&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What does an asynchronous call mean?
&lt;/h2&gt;

&lt;p&gt;The asynchronous call mentioned here mainly refers to two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Async component loading&lt;/li&gt;
&lt;li&gt;Send an async request to fetch data from the API&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Waiting for the loading of async components
&lt;/h2&gt;

&lt;p&gt;In fact, in &lt;code&gt;Vue&lt;/code&gt; the async component already supports displaying the &lt;code&gt;loading&lt;/code&gt; component during the loading process. The following code is taken from the official website:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="c1"&gt;// async component&lt;/span&gt;
        &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="c1"&gt;// loading component&lt;/span&gt;
        &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LoadingComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// delay&lt;/span&gt;
        &lt;span class="na"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:::tip&lt;br&gt;
&lt;code&gt;delay&lt;/code&gt; is used to specify the delay time for displaying the &lt;code&gt;loading&lt;/code&gt; component. The delay time in the above code is &lt;code&gt;200ms&lt;/code&gt;. If the loading of the asynchronous component is completed within &lt;code&gt;200ms&lt;/code&gt;, the &lt;code&gt;loading&lt;/code&gt; component has no chance to be displayed.&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;But it has two problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1、The &lt;code&gt;loading&lt;/code&gt; component is closely tied to the async component, and the &lt;code&gt;loading&lt;/code&gt; component cannot be promoted to a higher level and used for loading multiple asynchronous components.&lt;/li&gt;
&lt;li&gt;2、If the async component itself still has asynchronous calls, such as the request API, the hiding of the &lt;code&gt;loading&lt;/code&gt; component will not wait for the API request to complete.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;vue-async-manager&lt;/code&gt; provides the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component to solve the above two problems.&lt;/p&gt;
&lt;h3&gt;
  
  
  1、Create an async component using the &lt;code&gt;lazy&lt;/code&gt; function
&lt;/h3&gt;

&lt;p&gt;In the past, the way we created an async component was：&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asyncComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async.component.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we use the &lt;code&gt;lazy&lt;/code&gt; function provided by &lt;code&gt;vue-async-manager&lt;/code&gt; to create the async component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asyncComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async.component.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As shown in the code above, just pass the original asynchronous factory function as a parameter to the &lt;code&gt;lazy&lt;/code&gt; function.&lt;/p&gt;

&lt;h3&gt;
  
  
  2、Wrap async components with the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Use the Suspense component to wrap a component tree that may have async components --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;Suspense&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- Loading slot --&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;loading&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- Async component --&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;asyncComponent1/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;asyncComponent2/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/Suspense&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// Create async components&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asyncComponent1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async.component1.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asyncComponent2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async.component2.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Registration component&lt;/span&gt;
    &lt;span class="nx"&gt;asyncComponent1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;asyncComponent2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;loading&lt;/code&gt; component will only disappear after both &lt;code&gt;&amp;lt;asyncComponent1/&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;asyncComponent2/&amp;gt;&lt;/code&gt; have been loaded.&lt;/p&gt;

&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#waiting-for-all-async-components-to-load"&gt;Waiting for all async components to load&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;
&lt;h2&gt;
  
  
  Use with vue-router
&lt;/h2&gt;

&lt;p&gt;When we develop the &lt;code&gt;Vue&lt;/code&gt; application, the most common way to use asynchronous components is to do code splitting with &lt;code&gt;vue-router&lt;/code&gt;, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;VueRouter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async-component.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order for the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component to wait for the loading of this async component, we can wrap this async component factory function with the &lt;code&gt;lazy&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;VueRouter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./my-async-component.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we only need to wrap the &lt;code&gt;&amp;lt;router-view&amp;gt;&lt;/code&gt; component with the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Suspense&lt;/span&gt; &lt;span class="na"&gt;:delay=&lt;/span&gt;&lt;span class="s"&gt;"200"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;loading&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;router-view/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Suspense&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#use-with-vue-router"&gt;With vue-router&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;
&lt;h2&gt;
  
  
  How to display loading in the API request
&lt;/h2&gt;

&lt;p&gt;In the past, we usually manually maintained whether to show &lt;code&gt;loading&lt;/code&gt;, for example, when the "request to start", the &lt;code&gt;loading&lt;/code&gt; was displayed. Hide the &lt;code&gt;loading&lt;/code&gt; when "end of request". And if there are multiple requests for concurrency, you have to wait for all requests to complete before hiding &lt;code&gt;loading&lt;/code&gt;. In short, you need to maintain the state of &lt;code&gt;loading&lt;/code&gt; yourself, whether it is stored in the component or in &lt;code&gt;store&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now let's see how &lt;code&gt;vue-async-manager&lt;/code&gt; solves the &lt;code&gt;loading&lt;/code&gt; display problem in the API request process, assuming the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Suspense&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;loading...&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;MyComponent/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Suspense&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;MyComponent&amp;gt;&lt;/code&gt; component is rendered inside the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component, which is a normal component. Inside the  &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component, an API request is sent, as shown in the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- MyComponent.vue --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Display data --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;{{ res }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;res&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Fetch data&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the code we often see, usually we send async requests in the &lt;code&gt;created&lt;/code&gt; or &lt;code&gt;mounted&lt;/code&gt; hooks. However, for the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component, it does not know that it needs to wait for the async requests to complete before hiding the &lt;code&gt;loading&lt;/code&gt;. To solve this problem, we can create a &lt;strong&gt;resource manager&lt;/strong&gt; using the &lt;code&gt;createResource&lt;/code&gt; function provided by &lt;code&gt;vue-async-manager&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Display data --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;{{ $rm.$result }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager(rm)&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="c1"&gt;// Read data&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pass a factory function to the &lt;code&gt;createResource&lt;/code&gt; function, we create a &lt;strong&gt;resource manager&lt;/strong&gt;: &lt;code&gt;$rm&lt;/code&gt;, and then call the resource manager's &lt;code&gt;$rm.read()&lt;/code&gt; function to read the data. Note that the above code is written in a synchronous manner, and the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component knows that the component is making an async call, so the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component will wait for the async call to complete before hiding &lt;code&gt;loading&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;In addition, we see the template part of the above code, the data we show is &lt;code&gt;$rm.$result&lt;/code&gt;, in fact, after the async data is successfully acquired, the obtained data will be saved in the &lt;code&gt;$rm.$result&lt;/code&gt; property, it's important to note that the property itself is reactive, so you don't need to declare it in the &lt;code&gt;data&lt;/code&gt; option of the component.&lt;/p&gt;




&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#suspense-waits-for-rm-to-fetch-data"&gt;Suspense component waits for resource manager to fetch data&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;
&lt;h2&gt;
  
  
  Use with vuex
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;vuex&lt;/code&gt; it's very simple, just use &lt;code&gt;mapActions&lt;/code&gt; to map &lt;code&gt;actions&lt;/code&gt; to methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AsyncComponent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;mapActions&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;increase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;increase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#use-with-vuex"&gt;Use with vuex&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;
&lt;h2&gt;
  
  
  Capture all async calls in the component tree
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component not only captures the loading of async components. If an async component itself has other async calls, such as reading data through the &lt;strong&gt;Resource Manager&lt;/strong&gt;, the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component can also capture these async calls and wait for all async calls to end before hiding &lt;code&gt;loading&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;Let's look at an example：&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Suspense&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;loading&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- MyLazyComponent is a component created by the lazy function --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;MyLazyComopnent/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Suspense&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;MyLazyComopnent/&amp;gt;&lt;/code&gt; component is a component created by the &lt;code&gt;lazy&lt;/code&gt; function, so the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component can wait for the async component to load, whereas the async component itself reads the data through the &lt;strong&gt;resource manager&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Async component&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Read data through the resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component will wait for the completion of both asynchronous calls before hiding &lt;code&gt;loading&lt;/code&gt;, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1、Async component loading&lt;/li&gt;
&lt;li&gt;2、Async requests sent by &lt;strong&gt;Resource Manager&lt;/strong&gt; within the async component&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#suspense-waits-for-rm-to-fetch-data"&gt;Suspense component waits for resource manager to fetch data&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;
&lt;h2&gt;
  
  
  Resource manager
&lt;/h2&gt;

&lt;p&gt;We have been emphasizing a word: &lt;strong&gt;Resource Manager&lt;/strong&gt;，the return value of the &lt;code&gt;createResource&lt;/code&gt; function is a resource manager, which is an object, we usually use &lt;code&gt;$rm&lt;/code&gt; to name.&lt;/p&gt;

&lt;p&gt;The complete form of the resource manager is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(){},&lt;/span&gt;   &lt;span class="c1"&gt;// A function that calls this function to actually send an async request to fetch data&lt;/span&gt;
    &lt;span class="nx"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// The initial value is null. After the async data is successfully acquired, the obtained data is stored.&lt;/span&gt;
    &lt;span class="nx"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="c1"&gt;// The initial value is null, which holds the err data when the async request fails.&lt;/span&gt;
    &lt;span class="nx"&gt;$loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// A boolean value with an initial value of false, indicating whether the request is in progress&lt;/span&gt;
    &lt;span class="nf"&gt;fork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;      &lt;span class="c1"&gt;// Create a new resource manager based on an existing resource manager&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;$rm.read()&lt;/code&gt; function is used to send async requests to fetch data, which can be called multiple times, such as clicking the button to call it again. &lt;code&gt;$rm.$result&lt;/code&gt; we have also seen it, which is used to store data obtained asynchronously. &lt;code&gt;$rm.$loading&lt;/code&gt; is a Boolean value that indicates whether the request is in progress. Usually we can customize the &lt;code&gt;loading&lt;/code&gt; display like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Control loading display --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;MyButton&lt;/span&gt; &lt;span class="na"&gt;:loading=&lt;/span&gt;&lt;span class="s"&gt;"$rm.$loading"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;提交&lt;span class="nt"&gt;&amp;lt;/MyButton&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:::tip&lt;br&gt;
More importantly: &lt;strong&gt;the &lt;code&gt;createResource()&lt;/code&gt; can be used separately from &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt;.&lt;/strong&gt;&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;If the resource manager has encountered an error while fetching data, the error data is stored in the &lt;code&gt;$rm.$error&lt;/code&gt; property. The &lt;code&gt;$rm.fork()&lt;/code&gt; function is used to create an identical resource manager based on the existing &lt;strong&gt;resource manager&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fork a resource manager
&lt;/h2&gt;

&lt;p&gt;When an API is used to fetch data, and we need to fetch data twice, we only need to call &lt;code&gt;$rm.read()&lt;/code&gt; twice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="c1"&gt;// Continuous fetch data twice&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;top&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bottom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But doing so will create a problem, since one &lt;strong&gt;resource manager&lt;/strong&gt; is associated with only one &lt;code&gt;$rm.$result&lt;/code&gt;, so in the above code, &lt;code&gt;$rm.$result&lt;/code&gt; will only save the data of &lt;code&gt;$rm.read('bottom')&lt;/code&gt;. Of course, sometimes this is expected, but if you need to store the data twice called, you need &lt;code&gt;fork&lt;/code&gt; to create a new resource manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="c1"&gt;// Fork a new resource manager based on the existing resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;// The data read twice will be stored separately&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;top&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bottom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, since &lt;code&gt;$rm&lt;/code&gt; and &lt;code&gt;$rm2&lt;/code&gt; are two separate resource managers, they do not affect each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;prevent&lt;/code&gt; option &amp;amp; duplicate submissions
&lt;/h2&gt;

&lt;p&gt;Suppose we are submitting a form. If the user clicks the button twice, it will cause duplicate submissions, as in the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In fact, we can provide the &lt;code&gt;prevent&lt;/code&gt; option when creating the resource manager, so the created resource manager will automatically prevent duplicate submissions for us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAsyncData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a resource manager with the prevent option&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createResource&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAsyncData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prevent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$rm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a button is clicked for the first time, a request is sent and all new requests that occur before the request is completed are ignored.&lt;/p&gt;

&lt;h2&gt;
  
  
  loading style
&lt;/h2&gt;

&lt;p&gt;The style of &lt;code&gt;loading&lt;/code&gt; can be divided into two types: one is to display only &lt;code&gt;loading&lt;/code&gt; and not to display other content; the other is to display &lt;code&gt;loading&lt;/code&gt; while rendering other content normally, such as a long loading bar at the top of the page. This load bar does not affect the normal rendering of other content.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;vue-async-manager&lt;/code&gt; provides two rendering modes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;VueAsyncManager&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-async-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;VueAsyncManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Specify the rendering mode, the optional value is 'visible' | 'hidden', the default value is: 'visible'&lt;/span&gt;
  &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visible&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rendering mode of &lt;code&gt;'visible'&lt;/code&gt; is used by default. This means that &lt;code&gt;loading&lt;/code&gt; can coexist with other content. If you don't want this rendering mode, you can specify &lt;code&gt;mode&lt;/code&gt; to &lt;code&gt;'hidden'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So far, we have only seen the use of &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; components to control the display of &lt;code&gt;loading&lt;/code&gt;, and the contents of &lt;code&gt;loading&lt;/code&gt; are determined by the &lt;code&gt;fallback&lt;/code&gt; slot of the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component. But sometimes we want to be more flexible, we often encounter such a scenario: when you click the button and display a tiny &lt;code&gt;loading&lt;/code&gt; icon on the button, our code might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;MyButton&lt;/span&gt; &lt;span class="na"&gt;:loading=&lt;/span&gt;&lt;span class="s"&gt;"isLoading"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/MyButton&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The style of &lt;code&gt;loading&lt;/code&gt; is provided by the &lt;code&gt;&amp;lt;MyButton&amp;gt;&lt;/code&gt; component，in other words, we abandoned the &lt;code&gt;fallback&lt;/code&gt; slot of &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; as &lt;code&gt;loading&lt;/code&gt; to show. Therefore, we need to know if it is currently loading. We have already introduced the solution to this problem, we can use the resource manager's &lt;code&gt;$rm.$loading&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;MyButton&lt;/span&gt; &lt;span class="na"&gt;:loading=&lt;/span&gt;&lt;span class="s"&gt;"$rm.$loading"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/MyButton&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Error handling
&lt;/h2&gt;

&lt;p&gt;When the &lt;code&gt;lazy&lt;/code&gt; component fails to load, the &lt;code&gt;error&lt;/code&gt; slot of the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component is displayed. You can also customize the error handling by listening to the &lt;code&gt;rejected&lt;/code&gt; event of &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#load-failed-to-show-error-slot"&gt;Load failed to show error slot&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;In addition to displaying the &lt;code&gt;error&lt;/code&gt; slot when an error occurs, you can also customize the processing by listening to the &lt;code&gt;rejected&lt;/code&gt; event of the &lt;code&gt;&amp;lt;Suspense&amp;gt;&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;Suspense&lt;/span&gt; &lt;span class="na"&gt;:delay=&lt;/span&gt;&lt;span class="s"&gt;"200"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;rejected=&lt;/span&gt;&lt;span class="s"&gt;"handleError"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;loading&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AsyncComponent/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/Suspense&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ......&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;handleError&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Custom behavior&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:::tip&lt;br&gt;
Live Demo: &lt;a href="///demo.html#through-event-processing-error"&gt;Through event processing error&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;

&lt;h2&gt;
  
  
  About LRU Cache
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;React Cache&lt;/code&gt; uses the &lt;code&gt;LRU&lt;/code&gt; algorithm to cache resources, which requires the API to be idempotent. However, in my working environment, there are very few APIs that are really idempotent in a given time period, so there is no provision for caching resources ability.&lt;/p&gt;

</description>
      <category>vue</category>
    </item>
  </channel>
</rss>
