Page Loading state processing method and device and medium
By defining the Loading state management module and mutation function in Vuex and calling it in Axios interceptor, the unified problem of Loading state management during concurrent requests in multiple interfaces in Vue page is solved, and the user experience and code maintainability are improved.
Patent Information
- Application Number
- CN202411079229.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-11-01
AI Technical Summary
In the Vue page, the Loading status of each request cannot be managed uniformly when multiple interfaces concurrently request, resulting in a decline in user experience, and the code needs to be repeatedly modified in multiple components to adjust the Loading status.
The state management module and mutation functions used to manage the Loading state are defined in the state management library Vuex, and these functions are called in the interceptor of Axios. The centralized management and automatic processing of the Loading state is realized through the isLoading and pendingRequestsCount parameters, and the Loading component is created. Status is displayed or hidden.
It realizes unified management of Loading status when multiple interfaces are concurrently requested, improves user experience, simplifies code maintenance, avoids repeated writing of the same code, and improves maintainability.
Smart Images

Figure CN118885683A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Web front-end technology, and in particular to a method, device and medium for processing a page loading state. Background Art
[0002] Vue is a popular front-end framework that provides a declarative approach to building user interfaces.
[0003] When there are concurrent requests from multiple interfaces on the current Vue page, the application corresponding to each request communicates with the backend separately, and each has a Loading state. These Loading states cannot be managed uniformly, and the progress of each request processing is different, resulting in different Loading states corresponding to each request. When these Loading states are displayed separately on the Vue page, on the one hand, it will cause users to be dazzled and the user experience will be reduced. On the other hand, when related functions need to be modified or expanded, the code in multiple components / applications needs to be modified multiple times to achieve all adjustments to the Loading state. Summary of the invention
[0004] The present invention provides a method, device and medium for processing a page loading state, which are used to solve at least one of the above-mentioned technical problems.
[0005] The present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a method for processing a page Loading state, the method comprising: defining a state management module for managing the Loading state in a state management library Vuex; defining a mutation function for adjusting the state management module in the state management library Vuex; in an Axios interceptor, adjusting the parameters of the state management module by calling the mutation function to realize the processing of the Loading state; creating a Loading component, and displaying or hiding the Loading component according to the processing result of the Loading state.
[0007] In a possible implementation of the present invention, the state management module defined for managing the Loading state includes: defining an isLoading parameter and a pendingRequestsCount parameter of the state management module in the state management library Vuex; the isLoading parameter is used to indicate whether there is an interface request in progress, if so, the value of the isLoading parameter is true, if not, the value of the isLoading parameter is false; the pendingRequestsCount parameter is used to indicate the number of currently unfinished interface requests.
[0008] In a possible implementation of the present invention, the definition of the mutation function for adjusting the state management module includes: defining a mutation function for adjusting the parameters of the state management module in the state management library Vuex, and the parameters of the state management module include at least an isLoading parameter and a pendingRequestsCount parameter.
[0009] In a possible implementation of the present invention, the mutation function defined for adjusting the parameters of the state management module includes: defining INCREAST_PENDING_REQUESTS function, DECREAST_PENDING_REQUESTS function and SET_LOADING function in the state management library Vuex; the INCREAST_PENDING_REQUESTS function is used to add 1 to the value of the pendingRequestsCount parameter when the interface request starts; the DECREAST_PENDING_REQUESTS function is used to reduce the value of the pendingRequestsCount parameter by 1 when the interface request is completed; the SET_LOADING function is used to adjust the value of the isLoading parameter according to the value of the pendingRequestsCount parameter.
[0010] In a possible implementation of the present invention, the value of the isLoading parameter is adjusted according to the value of the pendingRequestsCount parameter, including: when the value of the pendingRequestsCount parameter is 0, the SET_LOADING function adjusts the value of the isLoading parameter to false; otherwise, the value of the isLoading parameter is adjusted to true.
[0011] In a possible implementation of the present invention, the processing of implementing the Loading state includes:
[0012] In the Axios interceptor, it is determined that there are concurrent interface requests; when the concurrent interface requests begin, the INCREAST_PENDING_REQUESTS function in the state management library Vuex is called to adjust the value of the pendingRequestsCount parameter to the number of concurrent interface requests; when any interface request is completed, the DECREAST_PENDING_REQUESTS function in the state management library Vuex is called to reduce the pendingRequestsCount parameter value by 1.
[0013] In a possible implementation of the present invention, the method further includes: determining whether the value of the pendingRequestsCount parameter is 0; if so, calling the SET_LOADING function in the state management library Vuex, and adjusting the value of the isLoading parameter to false through the SET_LOADING function.
[0014] In a possible implementation of the present invention, after adjusting the value of the isLoading parameter, the method further includes: if the value of the isLoading parameter is false, hiding the Loading component on the Vue page, otherwise, displaying the Loading component; when displayed, the Loading component is used to display the Loading animation on the Vue page.
[0015] In a second aspect, the present invention also provides a device for processing the page Loading state, the device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor so that the at least one processor can execute: defining a state management module for managing the Loading state in the state management library Vuex; defining a mutation function for adjusting the state management module in the state management library Vuex; in the Axios interceptor, adjusting the parameters of the state management module by calling the mutation function to realize the processing of the Loading state; creating a Loading component, and displaying or hiding the Loading component according to the processing result of the Loading state.
[0016] In a third aspect, the present invention also provides a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to be able to execute: defining a state management module for managing the Loading state in the state management library Vuex; defining a mutation function for adjusting the state management module in the state management library Vuex; in an Axios interceptor, adjusting the parameters of the state management module by calling the mutation function to realize the processing of the Loading state; creating a Loading component, and displaying or hiding the Loading component according to the processing result of the Loading state.
[0017] The present invention provides a method, device and medium for processing a page loading state, which has the following features:
[0018] Beneficial effects:
[0019] 1) By centrally managing the Loading status of concurrent requests from multiple interfaces, the Loading status is displayed when the request starts and hidden when all requests are completed, which improves the user experience. By displaying the Loading status on the page, users can clearly know that the application is communicating with the backend, thus avoiding unnecessary waiting and anxiety.
[0020] 2) Simplifies the code. By centrally managing the Loading status of all requests in Vuex and automatically handling these Loading status in the Axios interceptor, you can avoid repeating the same code in multiple components.
[0021] 3) Improved maintainability. Since the management of the Loading state is centralized, when you need to modify or expand related functions, you only need to modify them in the interceptors of Vuex and Axios, without modifying the code of multiple components. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0023] Figure 1 A flow chart of a method for processing a page loading state provided by the present invention;
[0024] Figure 2A processing diagram of a page loading state provided by the present invention;
[0025] Figure 3 A schematic diagram of the structure of a page loading state processing device provided by the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0027] Vue is a popular front-end framework that provides a declarative approach to building user interfaces. Vuex is a state management model and library for Vue that uses centralized storage to manage the states of all components of an application. Axios is a Promise-based network request library for http communication between browsers and node.js. The Loading state processing method in the present invention implements unified management of the Loading state in the scenario of concurrent requests of multiple interfaces, so that the Loading state is displayed at the beginning of the request and hidden when all requests are completed.
[0028] The method of the present invention is described in detail below with reference to the accompanying drawings.
[0029] Figure 1 A flow chart of a method for processing a page loading state provided by the present invention, such as Figure 1 As shown, the Loading state processing method in the present invention at least includes the following execution steps:
[0030] Step 101. Define a state management module for managing the Loading state in the state management library Vuex.
[0031] The Loading state processing method proposed in the present invention first defines a state management module in the state management library Vuex. The module mainly manages the Loading state through two parameters. The so-called definition of the state management module is to define these two parameters.
[0032] In one possible implementation of the present invention, when defining the state management module, the isLoading parameter and the pendingRequestsCount parameter are defined in the state management library Vuex, wherein the isLoading parameter is used to indicate whether there is an interface request in progress on the Vue page. If so, the value of the isLoading parameter is adjusted to true; if not, the value of the isLoading parameter is adjusted to false; and the pendingRequestsCount parameter is used to indicate the number of currently unfinished or unprocessed interface requests.
[0033] Step 102: Define a mutation function for adjusting the state management module in the state management library Vuex.
[0034] After defining the state management module, in order to adjust the above two parameters, you need to continue to define the mutation function in the state management library Vuex, and adjust the value of the isLoading parameter and the pendingRequestsCount parameter according to the progress of the interface request by calling the mutation function.
[0035] In a possible implementation of the present invention, the aforementioned mutation function is specifically defined as follows: INCREAST_PENDING_REQUESTS function, DECREAST_PENDING_REQUESTS function and SET_LOADING function are defined in the state management library Vuex, wherein the INCREAST_PENDING_REQUESTS function is used to adjust the value of the pendingRequestsCount parameter to increase when the interface request starts, for example, adjusting the parameter value by 1, and the DECREAST_PENDING_REQUESTS function is used to adjust the value of the pendingRequestsCount parameter to decrease when the interface request is completed, for example, adjusting the parameter value by 1, and the SET_LOADING function is used to adjust the value of the isLoading parameter according to the value of the pendingRequestsCount parameter.
[0036] Furthermore, the adjustment principle of the SET_LOADING function is as follows: when the value of the pendingRequestsCount parameter is 0, it means that no interface request is in progress at this time, and the value of the isLoading parameter is adjusted to false. When the value of the pendingRequestsCount parameter is not 0, it means that there are still interface requests in progress at this time, and the value of the isLoading parameter needs to be adjusted to true.
[0037] Step 103: In the Axios interceptor, the parameters of the state management module are called through the mutation function to implement the processing of the Loading state.
[0038] After defining the state management module and several mutation functions in the state manager Vuex, you can implement the processing of the Loading state in the Axios interceptor. Specifically, first determine whether there are concurrent interface requests on the Vue page. The so-called concurrency refers to interface requests that are started or performed together. When concurrent interface requests begin, call the INCREAST_PENDING_REQUESTS function in the state management library Vuex. Through this function, the value of the pendingRequestsCount parameter is adjusted to the number of concurrent interface requests. This is because the pendingRequestsCount parameter indicates the number of currently unfinished interface requests. When interface requests start to be performed concurrently, the number of concurrent requests is the number of unfinished interface requests. After that, every time an interface request is completed, the DECREAST_PENDING_REQUESTS function is called once. The pendingRequestsCount parameter value is adjusted by 1 through this function. After the adjustment is completed, it is detected whether the value of the pendingRequestsCount parameter is 0. If it is 0, the SET_LOADING function in the state management library Vuex is called. The value of the isLoading parameter is adjusted to false through the SET_LOADING function. If it is not 0, the completion of the interface request continues to be monitored.
[0039] Step 104: Create a Loading component, and display or hide the Loading component according to the processing result of the Loading state.
[0040] In one possible implementation of the present invention, a Loading animation is displayed on the front-end Vue page to prompt the user that an interface request is being processed. The Loading animation here can be implemented by creating a Loading component. The creation process can refer to the existing component creation scheme, and the present invention will not be repeated here. At the same time, the display or hiding of the Loading component is determined by the value of the isLoading parameter. Specifically, if the value of the isLoading parameter is false, it means that there is no unfinished interface request, then the aforementioned Loading component is hidden on the Vue page, that is, the Loading animation is not displayed on the Vue page. If the value of the isLoading parameter is true, it means that there is still an unfinished interface request, then the aforementioned Loading component is displayed on the Vue page, that is, the Loading animation is displayed on the Vue page to prompt the user.
[0041] That is, the Loading component in the present invention can be displayed when the interface request starts and hidden after all the interface requests are completed, thereby achieving unified and centralized management of interface requests.
[0042] Figure 2 A processing diagram of a page loading state provided by the present invention. Figure 2 As shown, the Loading state processing in the present invention may also include the following process:
[0043] First, define a module for managing the Loading state in the state management library Vuex. This module should contain at least two parameters: isLoading and pendingRequestsCount. isLoading is used to indicate whether there is an interface request in progress, and pendingRequestsCount is used to record the number of currently unfinished interface requests; at the same time, mutation functions should be defined in the state management library Vuex: INCREAST_PENDING_REQUESTS, DECREAST_PENDING_REQUESTS and SET_LOADING, which are used to update the status of the aforementioned isLoading and pendingRequestsCount. Among them, the INCREAST_PENDING_REQUESTS function is used to increase the value of pendingRequestsCount when the interface request starts, the DECREAST_PENDING_REQUESTS function is used to reduce the value of pendingRequestsCount when the interface request is completed, and the SET_LOADING function is used to set the isLoading state to false or true according to the value of pendingRequestsCount.
[0044] When there are concurrent interface requests on the Vue page, when the interface request starts, the INCREAST_PENDING_REQUESTS function defined by Vuex is called in the Axios interceptor to increase the value of pendingRequestsCount; when the request is completed (whether successful or failed), the DECREAST_PENDING_REQUESTS function is still called to reduce the value of pendingRequestsCount. At the same time, after each call, the value of pendingRequestsCount is checked. If the value is 0, SET_LOADING is called to set isLoading to false, and if the value is greater than 0, SET_LOADING is called to set isLoading to true.
[0045] After that, the value of isLoading is obtained through Vuex's getters, and based on this value, it is decided whether to display the Loading component (which is applied to the Vue page). Specifically, the Loading component is displayed when the value of isLoading is true, and the Loading component is hidden when the value of isLoading is false.
[0046] Based on the same inventive concept, the present invention also provides a device for processing a page loading state, the structure of which is as follows: Figure 3 shown.
[0047] Figure 3 A schematic diagram of the structure of a processing device for a page loading state provided by the present invention. Figure 3 As shown, the page Loading state processing device 300 in the present invention specifically includes: at least one processor 301; and a memory 303 that is communicatively connected to the at least one processor 301 (connected via a bus 302); wherein the memory 303 stores instructions that can be executed by the at least one processor 301, so that the at least one processor 301 can execute a page Loading state processing method as described in any of the above embodiments.
[0048] In a possible implementation of the present invention, the aforementioned processor is used to execute: define a state management module for managing the Loading state in the state management library Vuex; define a mutation function for adjusting the state management module in the state management library Vuex; in the Axios interceptor, adjust the parameters of the state management module by calling the mutation function to realize the processing of the Loading state; create a Loading component, and display or hide the Loading component according to the processing result of the Loading state.
[0049] In addition, the present invention also provides a non-volatile computer storage medium storing computer executable instructions, characterized in that the computer executable instructions are configured to be able to execute a method for processing a page loading state as described in any of the above embodiments.
[0050] In one possible implementation of the present invention, the aforementioned computer executable instructions are set to execute, a state management module for managing the Loading state is defined in the state management library Vuex; a mutation function for adjusting the state management module is defined in the state management library Vuex; in the Axios interceptor, the parameters of the state management module are adjusted by calling the mutation function to realize the processing of the Loading state; a Loading component is created, and the Loading component is displayed or hidden according to the processing result of the Loading state.
[0051] Each embodiment of the present invention is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the IoT device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0052] The device and medium provided by the present invention correspond one-to-one to the method, so the device and medium also have similar beneficial technical effects to the corresponding methods. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the system and medium will not be repeated here.
[0053] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0054] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0055] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0056] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0057] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0058] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0059] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0060] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0061] The above are only embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for processing a page loading state, characterized in that: The method comprises: Define a state management module for managing the Loading state in the state management library Vuex; Define a mutation function for adjusting the state management module in the state management library Vuex; In the Axios interceptor, the parameters of the state management module are adjusted by calling the mutation function to implement the processing of the Loading state; A Loading component is created, and the Loading component is displayed or hidden according to a processing result of the Loading state.
2. A method for processing a page loading state according to claim 1, characterized in that: The state management module defined to manage the Loading state includes: Define the isLoading parameter and pendingRequestsCount parameter of the state management module in the state management library Vuex; The isLoading parameter is used to indicate whether an interface request is currently in progress. If so, the value of the isLoading parameter is true; if not, the value of the isLoading parameter is false; The pendingRequestsCount parameter is used to indicate the number of currently unfinished interface requests.
3. A method for processing a page loading state according to claim 1, characterized in that: The definition is used to adjust the mutation function of the state management module, including: A mutation function for adjusting parameters of the state management module is defined in the state management library Vuex, and the parameters of the state management module include at least an isLoading parameter and a pendingRequestsCount parameter.
4. A method for processing a page loading state according to claim 3, characterized in that: The mutation function defined to adjust the parameters of the state management module includes: Define INCREAST_PENDING_REQUESTS function, DECREAST_PENDING_REQUESTS function and SET_LOADING function in the state management library Vuex; The INCREAST_PENDING_REQUESTS function is used to increase the value of the pendingRequestsCount parameter by 1 when an interface request starts; The DECREAST_PENDING_REQUESTS function is used to reduce the value of the pendingRequestsCount parameter by 1 when the interface request is completed; The SET_LOADING function is used to adjust the value of the isLoading parameter according to the value of the pendingRequestsCount parameter.
5. A method for processing a page loading state according to claim 4, characterized in that: Adjusting the value of the isLoading parameter according to the value of the pendingRequestsCount parameter includes: When the value of the pendingRequestsCount parameter is 0, the SET_LOADING function adjusts the value of the isLoading parameter to false; otherwise, the SET_LOADING function adjusts the value of the isLoading parameter to true.
6. A method for processing a page loading state according to claim 2, characterized in that: The processing of implementing the Loading state includes: In the Axios interceptor, it is determined that there are concurrent interface requests; When the concurrent interface request begins, call the INCREAST_PENDING_REQUESTS function in the state management library Vuex, and adjust the value of the pendingRequestsCount parameter to the number of concurrent interface requests; When any interface request is completed, the DECREAST_PENDING_REQUESTS function in the state management library Vuex is called to reduce the pendingRequestsCount parameter value by 1.
7. A method for processing a page loading state according to claim 6, characterized in that: The method further comprises: Determine whether the value of the pendingRequestsCount parameter is 0; If so, the SET_LOADING function in the state management library Vuex is called, and the value of the isLoading parameter is adjusted to false through the SET_LOADING function.
8. A method for processing a page loading state according to claim 7, characterized in that: After adjusting the value of the isLoading parameter, the method further includes: If the value of the isLoading parameter is false, the Loading component is hidden on the Vue page, otherwise, the Loading component is displayed; The Loading component is used to display the Loading animation on the Vue page when displayed.
9. A device for processing a page loading state, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor to enable the at least one processor to: Define a state management module for managing the Loading state in the state management library Vuex; Define a mutation function for adjusting the state management module in the state management library Vuex; In the Axios interceptor, the parameters of the state management module are adjusted by calling the mutation function to implement the processing of the Loading state; A Loading component is created, and the Loading component is displayed or hidden according to a processing result of the Loading state.
10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: The computer executable instructions are configured to: Define a state management module for managing the Loading state in the state management library Vuex; Define a mutation function for adjusting the state management module in the state management library Vuex; In the Axios interceptor, the parameters of the state management module are adjusted by calling the mutation function to implement the processing of the Loading state; A Loading component is created, and the Loading component is displayed or hidden according to a processing result of the Loading state.
Citation Information
Patent Citations
Method, system and device for carrying out state management on vue and medium
CN111858314A
Unified interface abnormal error code processing method based on vue, vuex and axios
CN117880071A
Efficient calling of functions on a processor
US20150268960A1
