An advanced routing cache method, device and medium based on Vue components
By downgrading advanced routing information in the Vue framework, the problem of caching of third-level and above routes is solved, the caching of advanced routing is realized, the loading speed and user experience are improved, and the project's scalability and maintainability are enhanced. .
Patent Information
- Application Number
- CN202310287551.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-20
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2043-03-20
AI Technical Summary
In systems based on the Vue framework, advanced routes at level three and above cannot be effectively cached by keep-alive components, resulting in frequent re-rendering when components are switched, affecting loading speed and user experience.
By determining the subsystems and sub-routing files of the project system, obtain the routing information and levels of the sub-routing files, judge and downgrade advanced routing based on the preset level threshold, use Vue components to delete intermediate routing information, and update the array to achieve advanced routing Route cache.
It implements caching of advanced routing, avoids component re-rendering, improves loading speed and user experience, and enhances the project's scalability and maintainability.
Smart Images

Figure CN116304433B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an advanced routing caching method, device and medium based on a Vue component. Background Art
[0002] Vue is a progressive framework for building user interfaces. Vue is designed to be applied layer by layer from the bottom up. keep-alive is a built-in component of Vue that allows the included components to retain their state or avoid re-rendering, which is also known as component caching. keep-alive can also cache inactive components. In some cases, when a component is switched, it will be destroyed by default. If a component does not need to be destroyed after switching and the previous state needs to be saved, then keep-alive can be used to achieve this.
[0003] The essence of routing is a correspondence. Different resources are returned according to different URL requests. There is a correspondence between the URL address and the real resource, which is routing. Routes with a routing level of three or above are called advanced routing.
[0004] In the existing system projects based on the Vue framework, the system's sidebar includes parents, children, and sub-children. When using keep-alive, the Vue component keep-alive cannot cache advanced routes of the third level and above. Summary of the invention
[0005] In order to solve the above problems, the present application proposes an advanced routing cache billing method based on Vue components, including: determining a project system and multiple subsystems of the project system, and determining multiple sub-routing files corresponding to the multiple subsystems; obtaining the routing information and level of the sub-routing files through the Vue component, and judging the level according to a preset level threshold; if the level is greater than or equal to the level threshold, downgrading the level according to the routing information, and saving the downgraded sub-routing files.
[0006] In one example, the method further includes: determining a root directory of the project system, and establishing a routing folder in the root directory; and establishing a parent routing file in the routing folder to configure the child routing file in the parent routing file.
[0007] In one example, the method further includes: importing the multiple child routing files into the parent routing file.
[0008] In one example, before obtaining the routing information and the level of the sub-routing file through the Vue component, the method further includes: determining a preset array, placing the multiple sub-routing files into the array, so that the Vue component calls the multiple sub-routing files through the array.
[0009] In one example, the routing information includes but is not limited to a URL address.
[0010] In one example, before downgrading the level according to the routing information, the method further includes: determining the URL address corresponding to the sub-routing file according to the routing information; and determining intermediate routing information according to the URL address.
[0011] In one example, downgrading the level according to the routing information specifically includes: deleting the intermediate routing information in the routing information through the Vue component, thereby completing the downgrading of the level.
[0012] In one example, saving the downgraded sub-routing file specifically includes: updating an array according to the downgraded level and the deleted routing information.
[0013] On the other hand, the present application also proposes an advanced routing cache device based on Vue components, comprising: 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, and the instructions are executed by the at least one processor so that the advanced routing cache device based on the Vue component can execute: determining a project system and multiple subsystems of the project system, and determining multiple sub-routing files corresponding to the multiple subsystems; obtaining routing information and levels of the sub-routing files through the Vue component, and judging the level according to a preset level threshold; if the level is greater than or equal to the level threshold, downgrading the level according to the routing information, and saving the downgraded sub-routing file.
[0014] On the other hand, the present application also proposes a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to: determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems; obtain routing information and levels of the sub-routing files through a Vue component, and judge the level according to a preset level threshold; if the level is greater than or equal to the level threshold, downgrade the level according to the routing information, and save the downgraded sub-routing file.
[0015] This application creates a project root routing JS configuration file, which contains the routing configuration of the entire system project. This application reads the configuration file information through the global routing configuration center, and then calls the subsystem project registration route of the global routing, registers each subsystem project to the global routing configuration center, and stores the data information of the subsystem project. This application implements caching of advanced routes in the routing information of the subsystem project, enhances the scalability and maintainability of the project, avoids re-rendering of the page during component switching, improves loading speed, and optimizes user experience. . BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 A schematic diagram of a flow chart of an advanced routing caching method based on a Vue component in an embodiment of the present application;
[0018] Figure 2 This is a schematic diagram of an advanced routing cache device based on a Vue component in an embodiment of the present application. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0020] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0021] like Figure 1 As shown, in order to solve the above problems, an advanced routing caching method based on Vue components is provided in an embodiment of the present application, and the method includes:
[0022] In one embodiment, a project system of an enterprise has multiple levels of directories. For example, in an energy monitoring system of an enterprise, the enterprise performs energy monitoring and control, production scheduling and command, production safety monitoring, video monitoring and other operations through the energy monitoring system, and the energy monitoring system has multiple subsystems, including an integrated system, a machine well group control system, a park energy consumption system, a distribution room monitoring system, a photovoltaic power generation system, a wind power generation system, and an outdoor lighting control system.
[0023] In one embodiment, a parent routing file needs to be created in the root directory of the project system to implement the switching jump between pages. Then you need to create a new router folder under the root directory, and then create a new index.js file in the router folder. After the creation is completed, the configuration will be performed in index.js. The specific process is to import the Vue package and the Vue-router package, create VueRouter, and share the route externally.
[0024] S101. Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems.
[0025] The subsystem is a secondary system belonging to the project system. Each subsystem is a module or a project. Each subsystem has its own sub-level routing file, which includes all functional routing information under the subsystem. The functional routing information is the URL address accessed by the browser and the corresponding resource page. For example, the campus energy system subsystem introduces the power overview function component, path: ' / yqyn', which is the connection address of the URL accessed by our browser. When we enter this system through the browser, we can view the power overview function page. The routing file mainly maintains the correspondence between the URL and the resource page. Other systems are similar.
[0026] In one embodiment, a routing array is pre-set in the system code, and multiple sub-routing files are placed in the array, so that the Vue component calls multiple sub-routing files through the array. The data source in the array is the imported subsystem routing information. The array can be understood as a container, and the sub-routing files of each subsystem are placed in this container to achieve unified management of each system. When calling the array, the routing information of all subsystems can be obtained.
[0027] S102, obtaining the routing information and the level of the sub-routing file through the Vue component, and judging the level according to a preset level threshold.
[0028] The global routing method, router.beforeEach, is called in the system to extract and judge each routing information. The router.beforeEach method is a built-in method of Vue. In the front-end routing jump, the routing will pass through router.beforeEach before the jump, and router.beforeEach can get the routing information through the to parameter. Based on this feature, we can set some conditions in router.beforeEach to control the routing information. The essence of routing is a correspondence relationship, which returns different resources according to different URL requests. Routing information is a general term for a corresponding relationship between URL addresses and real resources.
[0029] S103: If the level is greater than or equal to the level threshold, downgrade the level according to the routing information, and save the downgraded sub-routing file.
[0030] The judgment is implemented through Vue's built-in to.matched method. The to.matched array stores all the matched routing information. Call Vue's built-in to.matched.length method to obtain routing information and determine the routing information that belongs to advanced routing. For example, if level 3 or above is defined as advanced routing, the level threshold is 3; routing with a level greater than or equal to 3 is advanced routing, and advanced routing needs to be downgraded.
[0031] In one embodiment, the Vue method to.matched.splice is called to clear the intermediate routing information. For example, the accessed URL is " / sys / manage / hello / user". Then the intermediate routing information is " / manage / hello".
[0032] In one embodiment, when the keep-alive component caches the URL address " / sys / manage / hello / user", it is a level 4 route, which will cause cache failure. By deleting the intermediate route information method, the level 4 route is reduced to a level 2 route, and the cache for the advanced route can be achieved.
[0033] like Figure 2 As shown, the embodiment of the present application also provides an advanced routing cache device based on the Vue component, including:
[0034] at least one processor; and,
[0035] a memory communicatively connected to the at least one processor; wherein,
[0036] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the advanced routing cache device based on the Vue component to perform:
[0037] Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems;
[0038] Obtain the routing information and level of the sub-routing file through the Vue component, and judge the level according to a preset level threshold;
[0039] If the level is greater than or equal to the level threshold, the level is downgraded according to the routing information, and the downgraded sub-routing file is saved.
[0040] The embodiment of the present application further provides a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured as follows:
[0041] Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems;
[0042] Obtain the routing information and level of the sub-routing file through the Vue component, and judge the level according to a preset level threshold;
[0043] If the level is greater than or equal to the level threshold, the level is downgraded according to the routing information, and the downgraded sub-routing file is saved.
[0044] Each embodiment in this application 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 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.
[0045] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects as the corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0046] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0047] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 generate 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.
[0048] 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.
[0049] 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 The steps for the functions specified in one or more boxes.
[0050] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0051] 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.
[0052] 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.
[0053] 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.
[0054] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. An advanced routing caching method based on Vue components, It is characterized in that include: Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems; Obtain the routing information and level of the sub-routing file through the Vue component, and judge the level according to a preset level threshold; If the level is greater than or equal to the level threshold, downgrading the level according to the routing information, and saving the downgraded sub-routing file; Determine the root directory of the project system, and create a routing folder in the root directory; Create a parent routing file in the routing folder to configure the child routing file in the parent routing file; Import the multiple child routing files into the parent routing file; Before obtaining the routing information and the number of levels of the sub-routing file through the Vue component, the method further includes: Determine a preset array, and put the multiple sub-routing files into the array, so that the Vue component calls the multiple sub-routing files through the array; Before downgrading the level according to the routing information, Determine the URL address corresponding to the sub-routing file according to the routing information; Determine intermediate routing information according to the URL address; Degrading the level according to the routing information specifically includes: The intermediate routing information in the routing information is deleted through the Vue component, thereby completing the downgrading of the level.
2. The method according to claim 1, It is characterized in that The routing information includes but is not limited to a URL address.
3. The method according to claim 1, It is characterized in that Saving the downgraded sub-route file specifically includes: The array is updated according to the downgraded level and the deleted routing information.
4. An advanced routing cache device based on Vue components, It is characterized in that include: at least one processor; as well as, 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, and the instructions are executed by the at least one processor to enable the advanced routing cache device based on the Vue component to perform: Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems; Obtain the routing information and level of the sub-routing file through the Vue component, and judge the level according to a preset level threshold; If the level is greater than or equal to the level threshold, downgrading the level according to the routing information, and saving the downgraded sub-routing file; Determine the root directory of the project system, and create a routing folder in the root directory; Create a parent routing file in the routing folder to configure the child routing file in the parent routing file; Import the multiple child routing files into the parent routing file; Before obtaining the routing information and level of the sub-routing file through the Vue component, Determine a preset array, and put the multiple sub-routing files into the array, so that the Vue component calls the multiple sub-routing files through the array; Before downgrading the level according to the routing information, Determine the URL address corresponding to the sub-routing file according to the routing information; Determine intermediate routing information according to the URL address; Degrading the level according to the routing information specifically includes: The intermediate routing information in the routing information is deleted through the Vue component, thereby completing the downgrading of the level.
5. A non-volatile computer storage medium storing computer executable instructions, It is characterized in that The computer executable instructions are configured to: Determine a project system and multiple subsystems of the project system, and determine multiple sub-routing files corresponding to the multiple subsystems; Obtain the routing information and level of the sub-routing file through the Vue component, and judge the level according to a preset level threshold; If the level is greater than or equal to the level threshold, downgrading the level according to the routing information, and saving the downgraded sub-routing file; Determine the root directory of the project system, and create a routing folder in the root directory; Create a parent routing file in the routing folder to configure the child routing file in the parent routing file; Import the multiple child routing files into the parent routing file; Before obtaining the routing information and level of the sub-routing file through the Vue component, Determine a preset array, and put the multiple sub-routing files into the array, so that the Vue component calls the multiple sub-routing files through the array; Before downgrading the level according to the routing information, Determine the URL address corresponding to the sub-routing file according to the routing information; Determine intermediate routing information according to the URL address; Degrading the level according to the routing information specifically includes: The intermediate routing information in the routing information is deleted through the Vue component, thereby completing the downgrading of the level.
