Front-end list rendering method and device, computer equipment and storage medium

CN118916557APending Publication Date: 2024-11-08联友智连科技有限公司

Patent Information

Application Number
CN202410971599.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When traditional front-end page rendering technology processes long lists, it leads to degradation in browser rendering performance, increased memory pressure, and poor user experience, especially when the amount of data is huge, resulting in lag and delay.

Method used

Using virtual scrolling and delay loading technology, the list data is divided into multiple data blocks, only data blocks in the visual area are rendered, data blocks that are about to enter the area are preloaded, data is processed using multi-threading, and data is minimized through CSS transformation and animation. DOM operation.

Benefits of technology

Significantly reduces the number of DOM operations and redraw/reorders, improves page rendering performance, avoids the problem of excessive memory usage, achieves a smooth scrolling experience and fast response, adapts to data sets and business needs of different scales, and is compatible with mainstream Browser and device.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916557A_ABST
    Figure CN118916557A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of front-end display, and relates to a front-end list rendering method and device, computer equipment and a storage medium, and the method comprises the steps: obtaining list data, dividing the list data into a plurality of data blocks, only rendering the data blocks in a visual area, and preloading the data blocks which are about to enter the visual area; according to the rolling behavior of the user, dynamically loading the data blocks, predicting the rolling direction and speed of the user, and loading a plurality of data blocks needing to be loaded in advance; packaging each list item into an independent component, and using a state management library to maintain and manage the state of the list; the processing frequency of the scrolling event is limited, and after the user stops scrolling for a period of time, the data block is loaded or rendered; starting multi-thread processing data at the background, and analyzing, filtering and sorting the data; the DOM operation frequency is minimized, and movement and hiding of the list items are achieved through CSS transformation and animation. The rendering performance of the page is improved, the memory usage is reduced, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of front-end display technology, and in particular to a front-end list rendering method, device, computer equipment and storage medium. Background Art

[0002] With the rapid development of Internet technology and the popularity of mobile devices, users have higher and higher expectations for Web applications. Especially in data-intensive application scenarios, such as product lists on e-commerce websites, information streams on social media, and article aggregation on news portals, users hope to browse large amounts of data quickly and smoothly. However, traditional front-end page rendering technology faces many challenges when processing long lists.

[0003] Traditional front-end page rendering usually adopts synchronous loading and one-time rendering, that is, all data is obtained when the page is loaded, and a complete DOM tree is constructed at one time. This method performs well when the amount of data is small, but when facing a long list, it will encounter the following problems: performance bottleneck: the creation and layout calculation of a large number of DOM nodes causes a sharp drop in browser rendering performance; memory pressure: a large number of DOM nodes occupy a large amount of memory, which may cause the browser to crash or respond slowly; poor user experience: long page loading time, freezes when scrolling, affecting user operation and browsing experience. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to propose a front-end list rendering method, device, computer equipment and storage medium to solve the problem of a sharp decline in browser rendering performance due to the creation and layout calculation of a large number of DOM nodes during traditional front-end page rendering.

[0005] In order to solve the above technical problems, the present invention provides a front-end list rendering method, which adopts the following technical solution, including the steps of:

[0006] Acquire list data, divide the list data into multiple data blocks, render only the multiple data blocks in the visible area, and preload the multiple data blocks that are about to enter the visible area;

[0007] According to the user's scrolling behavior, dynamically load multiple data blocks, predict the user's scrolling direction and speed, and load multiple data blocks that will be loaded in advance;

[0008] Encapsulate each list item as an independent component and use the state management library to maintain and manage the state of the list;

[0009] Limit the processing frequency of scrolling events, and load or render the data block after the user stops scrolling for a period of time;

[0010] Start multi-threaded data processing in the background to parse, filter and sort the data;

[0011] Minimize the number of DOM operations and use CSS transformations and animations to move and hide list items.

[0012] Preferably, the step of obtaining the list data, dividing the list data into a plurality of data blocks, rendering only the plurality of data blocks in the visible area, and preloading the plurality of data blocks that are about to enter the visible area specifically further comprises:

[0013] Get list data from the backend or local storage through API requests;

[0014] According to the height of the list items and the height of the visible area, the list data is divided into multiple data blocks, and the number of list items contained in each data block is determined;

[0015] By listening to scroll events and calculating the scroll position, only multiple data blocks within the visible area are rendered;

[0016] Preload multiple chunks of data that are about to enter the viewport.

[0017] Preferably, the step of dynamically loading the plurality of data blocks according to the user's scrolling behavior, predicting the user's scrolling direction and speed, and loading the plurality of data blocks that will be loaded in advance specifically includes:

[0018] Dynamically load multiple data blocks based on the user's scrolling behavior;

[0019] Predict the user's scrolling direction and speed, and load the data blocks that will be loaded in advance.

[0020] Preferably, the step of encapsulating each list item as an independent component and using a state management library to maintain and manage the state of the list specifically includes:

[0021] Define the list data structure;

[0022] Create a list item component;

[0023] Use the v-for directive to render the list;

[0024] Add a unique identifier key;

[0025] Introducing a state management library;

[0026] Define list states in the state management library;

[0027] Use state management libraries in components;

[0028] Encapsulation and reuse.

[0029] Preferably, the step of limiting the processing frequency of the scrolling event and loading or rendering the data block after the user stops scrolling for a period of time specifically further includes:

[0030] Listen for scroll events;

[0031] Record the scrolling time;

[0032] Compare time differences;

[0033] Perform a load or render operation.

[0034] Preferably, the step of starting multi-threaded data processing in the background and parsing, filtering and sorting the data specifically includes:

[0035] Data reception: The background service receives data from the database;

[0036] Multi-thread allocation: Based on the type and amount of data, the background service dynamically allocates multiple threads for parallel processing;

[0037] Data parsing: Each thread parses the assigned data and converts it into a data structure suitable for processing;

[0038] Data filtering: filter data according to the needs of the front end;

[0039] Data sorting: Sort the filtered data;

[0040] Data formatting: Format the sorted data into a format that can be recognized by the front end;

[0041] Data return: Return the formatted data to the front-end service.

[0042] Preferably, the step of minimizing the number of DOM operations and using CSS transformation and animation to move and hide list items specifically includes:

[0043] Use Vue.js's virtual DOM and Diff algorithm to minimize the number of DOM operations;

[0044] Optimize the list;

[0045] Add CSS styles and use CSS transitions;

[0046] Trigger a CSS animation.

[0047] In order to solve the above technical problems, the present invention also provides a front-end list rendering device, which adopts the following technical solution, including:

[0048] A preloading module, used for acquiring list data, dividing the list data into multiple data blocks, rendering only the multiple data blocks in the visible area, and preloading the multiple data blocks that are about to enter the visible area;

[0049] A loading module, used to dynamically load a plurality of the data blocks according to the user's scrolling behavior, predict the user's scrolling direction and speed, and load in advance a plurality of the data blocks that will be loaded;

[0050] The management module is used to encapsulate each list item as an independent component and use the state management library to maintain and manage the state of the list;

[0051] A limiting module, used to limit the processing frequency of scrolling events, and to load or render the data block after the user stops scrolling for a period of time;

[0052] The processing module is used to start multi-threaded data processing in the background to parse, filter and sort the data;

[0053] An optimization module that minimizes the number of DOM operations and uses CSS transformations and animations to move and hide list items.

[0054] In order to solve the above technical problems, the present invention also provides a computer device, which adopts the technical solution described below, including a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned front-end list rendering method when executing the computer-readable instructions.

[0055] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the technical solution described below, and stores computer-readable instructions on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned front-end list rendering method are implemented.

[0056] Compared with the prior art, the present invention has the following beneficial effects: through virtual scrolling and other optimization technologies, the number of DOM operations and redrawing / rearrangement times is significantly reduced, thereby improving the rendering performance of the page; it avoids loading and rendering all list items at once, effectively reducing memory usage, and reducing performance problems or application crashes caused by insufficient memory; it achieves a smooth scrolling experience without obvious freezes or delays, and can maintain smooth interaction even in the case of huge amounts of data, thereby improving the user experience; through delayed loading and intelligent preloading technology, the response speed of data is accelerated, and users can see the required information faster, and the response speed is accelerated; the design is flexible and easy to expand, and can adapt to data sets of different sizes and diversified business needs, and can be expanded Strong scalability; compatible with mainstream browsers and devices, ensuring wide user coverage and consistent experience, with strong compatibility; componentized design and the use of state management make the code more modular, easy to develop and maintain; through data consistency checks on the server and client, it ensures that the displayed data is accurate and up-to-date, and the accuracy of the data is guaranteed; developers can adjust the size of data blocks, loading strategies and other parameters according to specific needs to achieve customized rendering effects, with strong flexibility; by reducing the situation of requesting a large amount of data at one time, it reduces the burden on the server, improves the stability and scalability of the service, and reduces the burden on the server; the unified rendering solution and tool library enable developers to quickly implement long list functions, speed up development, and improve development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] In order to more clearly illustrate the scheme in the present invention, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0058] Figure 1 is a flow chart of an embodiment of the front-end list rendering method of the present invention;

[0059] Figure 2 It is a structural schematic diagram of an embodiment of a front-end list rendering device of the present invention;

[0060] Figure 3 It is a schematic structural diagram of an embodiment of a computer device of the present invention. DETAILED DESCRIPTION

[0061] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present invention; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present invention or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0062] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0063] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.

[0064] It should be noted that the front-end list rendering method provided in the embodiment of the present invention is generally executed by a server / terminal device, and accordingly, the front-end list rendering device is generally arranged in the server / terminal device.

[0065] It should be understood that the number of terminal devices, networks and servers is only illustrative. Depending on the implementation requirements, there can be any number of terminal devices, networks and servers.

[0066] Here are some explanations of terms:

[0067] Front-end: refers to the application running on the client, usually built with HTML, CSS, JavaScript, etc., responsible for user interface display and providing user experience.

[0068] Long List: refers to a large number of data items that need to be displayed on a web page. These data items are usually presented in the form of a list.

[0069] Virtual Scrolling: Only list items within the visible area are rendered, and other items are dynamically loaded based on the scroll position to improve performance.

[0070] Lazy Loading: Load data on demand. The corresponding data is loaded only when the user scrolls to a specific position.

[0071] Pagination: Divide the data into multiple pages, and users can load and view different parts of the data by navigating through the pages.

[0072] Infinite Scrolling: A scroll loading method that automatically loads more data when the user scrolls to the bottom of the list without turning pages.

[0073] Memory Consumption: The amount of memory used by an application while it is running. Excessive memory consumption may cause performance issues or application crashes.

[0074] Throttling: Limit the frequency of function execution, so that even if the triggering event is very frequent, it will only be executed once within a specified time interval.

[0075] Debouncing: Ensure that the function waits for a certain delay time before executing after the event is triggered. If the event is triggered again within this delay time, the timing starts again.

[0076] Front-end list rendering involves the dynamic display of data in the user interface (UI). Simply put, front-end list rendering refers to the process of presenting the data set (such as arrays, object lists, etc.) provided by the server to the user in the form of a list through front-end technologies (such as HTML, CSS, JavaScript, etc.).

[0077] In front-end development, data is usually not static, but needs to be dynamically updated based on user interaction or time changes. List rendering exists to achieve this purpose. It allows developers to display data sets (such as product lists, user information lists, etc.) transmitted by the backend in the form of lists on web pages, and interact with users through front-end technologies (such as event monitoring, DOM operations, etc.).

[0078] The implementation principle of front-end list rendering mainly relies on JavaScript's DOM operation technology. When the back-end data reaches the front-end, JavaScript will traverse the data and create corresponding DOM elements for each data item according to the preset template (such as HTML structure). Then, these DOM elements will be inserted into the specified position of the page to form a complete list.

[0079] Embodiment 1

[0080] Please refer to Figure 1 , shows a flow chart of an embodiment of the front-end list rendering method of the present invention. The front-end list rendering method comprises the following steps:

[0081] Step S1, obtaining list data, dividing the list data into multiple data blocks, rendering only the multiple data blocks in the visible area, and preloading the multiple data blocks that are about to enter the visible area.

[0082] In this embodiment, the electronic device (e.g., server / terminal device) on which the front-end list rendering method runs can receive the front-end list rendering request via a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAXX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.

[0083] In this embodiment, step S1, obtaining list data, dividing the list data into multiple data blocks, rendering only the multiple data blocks in the visible area, and preloading the multiple data blocks that are about to enter the visible area may also specifically include the following steps:

[0084] S11. Obtain list data from the backend or local storage through API request.

[0085] Use HTTP libraries such as fetch, axios, etc. to send a GET request to the backend or local storage to obtain the list data. The request URL and parameter settings can be set according to actual needs.

[0086] When obtaining list data, you need to ensure the accuracy and completeness of the list data and perform necessary preprocessing on the list data, such as deduplication and sorting. Parse the list data (such as JSON format) and perform necessary processing or conversion as required.

[0087] S12. Divide the list data into multiple data blocks according to the height of the list items and the height of the visible area, and determine the number of list items contained in each data block.

[0088] The purpose of this step is to dynamically load list data according to the user's visible area, improve rendering efficiency, and avoid loading too much data at one time. The division of data blocks can be dynamically calculated based on factors such as the height of the list items and the height of the visible area.

[0089] The preprocessed list data can be divided into multiple data blocks using the slice method of the array, and each data block corresponds to a renderable area.

[0090] S13, by monitoring the scrolling event and calculating the scrolling position, only rendering the multiple data blocks within the visible area.

[0091] When the user scrolls the list, new data blocks can be dynamically loaded and rendered according to the scroll position, and data blocks that have exceeded the visible area can be unloaded. List items are dynamically rendered according to the user's scrolling behavior, reducing the number of actual DOM nodes.

[0092] In this way, you can avoid loading and rendering all the data at once, which greatly reduces the browser's memory usage and rendering pressure, and improves the page's performance and user experience.

[0093] S14, pre-loading multiple data blocks that are about to enter the visible area.

[0094] To further improve the user experience, you can also preload the data blocks that are about to enter the visible area when the user scrolls the list. This can be achieved by determining the scroll direction and calculating the position of the preloaded data blocks in the scroll event processing function. By preloading data blocks, the content can be displayed immediately when the user scrolls to a new area, reducing waiting time and improving the smoothness of the page. It also reduces the amount of data loaded in the initial page, speeds up page loading, and improves the user experience.

[0095] Step S2, dynamically loading multiple data blocks according to the user's scrolling behavior, predicting the user's scrolling direction and speed, and loading multiple data blocks that will be loaded in advance.

[0096] In this embodiment, step S2 may further include the following steps:

[0097] S21. Dynamically load multiple data blocks according to the user's scrolling behavior.

[0098] Set up a backend data source that can provide paging or streaming data. Set up a state on the frontend to store the loaded list data and the current page number or loading status.

[0099] Initial render: When the component loads, request the first page of data and render that data onto the page using v-for (in Vue) or other list rendering methods.

[0100] Listen to the scrolling events of the page, and trigger the data loading logic when the user scrolls to the bottom of the page or close to the bottom.

[0101] In the scroll event processing function, check the current status (such as page number or loading status). If the conditions are met (such as the current page number is less than the total number of pages), send a request to the backend to obtain the next page of data. In this way, the list data is dynamically loaded.

[0102] Add the newly acquired data to the list of loaded data and update the front-end state. Then, re-render the list to display the newly loaded data, and update and render the data in this way.

[0103] It should be noted that in step S21, it is necessary to properly handle possible network errors or data format errors, and reasonably manage the front-end status to ensure the smoothness of the user experience, and perform error handling and status management.

[0104] S22: predict the user's scrolling direction and speed, and load the data blocks that will be loaded in advance.

[0105] Listen to the scrolling events of the scroll container (such as scroll events), and obtain the scrolling distance and direction through the event processing function.

[0106] In the scroll event processing function, the scroll speed can be calculated based on the continuous scrolling distance and time difference. This can be achieved by recording the time difference between two scroll events with a timestamp and dividing it by the scrolling distance difference, so that the scrolling speed can be calculated.

[0107] Based on the scrolling direction and speed, the user's next scrolling trend can be predicted. For example, if the user is scrolling down quickly, it can be predicted that the user may want to view more data below.

[0108] Based on the predicted scrolling trend, the data blocks that will be needed can be requested from the server in advance and loaded. This usually involves dynamically modifying request parameters, such as paging parameters or offsets, to obtain the corresponding data. This can achieve the purpose of loading data in advance.

[0109] In order to ensure that the loaded data blocks can be rendered on the page in a timely manner, virtual scrolling or incremental rendering can be combined to optimize the performance of loading and rendering.

[0110] By adopting step S2, data can be dynamically loaded according to the user's scrolling behavior, reducing the amount of data initially loaded, thereby performing delayed loading. The user's scrolling direction and speed can also be predicted, and the data blocks that will be loaded in advance can be loaded in advance, thereby performing intelligent preloading.

[0111] Step S3, encapsulate each list item as an independent component, and use the state management library to maintain and manage the state of the list.

[0112] In this embodiment, step S3, encapsulating each list item as an independent component, and using the state management library to maintain and manage the state of the list may specifically include the following steps:

[0113] S31. Define list data structure.

[0114] First, you need to define the data structure of the list in the data function of the Vue component. This data structure is usually an array, and each element in the array represents a list item.

[0115] S32. Create a list item component.

[0116] Next, create a new Vue component to represent the list item. This component should receive a prop containing the data of the list item. In the component's template, use this prop data to render the specific content of the list item.

[0117] S33. Use the v-for directive to render the list.

[0118] In the parent component, use the v-for directive to traverse the list data and create a new list item component instance for each list item. By passing the currently traversed list item data as a prop to the list item component, the data is bound to the component.

[0119] S34. Add a unique identification key.

[0120] In order to improve Vue's rendering performance, you need to add a unique key attribute when using the v-for directive. This key attribute is usually a value that can uniquely identify the list item, such as the ID of the list item. When the list data changes, Vue can quickly locate the list item that needs to be updated based on the key instead of re-rendering the entire list.

[0121] S35. Introduce the state management library.

[0122] As the project scale increases, data sharing and state management between components will become more and more complicated. To solve this problem, you can introduce a state management library, such as Vuex. Vuex can help realize data sharing and state management between components, thereby improving the maintainability and reusability of the code.

[0123] S36. Define the list status in the status management library.

[0124] In Vuex, you need to define a state in the store to save the list data. This state can be changed through mutation or asynchronously through action. At the same time, you also need to provide access methods to the list data in getter.

[0125] S37. Use state management library in components.

[0126] In the parent component, auxiliary functions such as mapState, mapMutations, and mapActions are used to obtain list data from Vuex, change list data, and trigger asynchronous operations. In this way, the list state in Vuex can be directly operated in the component without worrying about how the data is passed between components.

[0127] S38, encapsulation and reuse.

[0128] By encapsulating list items as independent components and using the state management library to maintain and manage the state of the list, code encapsulation and reuse can be achieved. In this way, when you need to render similar lists, you only need to reuse these components and state management logic without having to write code repeatedly. At the same time, due to the centralized state management feature of Vuex, data sharing and state management across components can also be easily achieved.

[0129] By adopting step S3, each list item is encapsulated as an independent component and managed in a componentized manner, which can improve code reusability and maintainability. The state management library is also used to maintain and manage the state of the list to ensure data consistency and responsiveness.

[0130] Step S4, limiting the processing frequency of the scrolling event, and loading or rendering the data block after the user stops scrolling for a period of time.

[0131] In this embodiment, step S4, limiting the processing frequency of the scrolling event, and loading or rendering the data block after the user stops scrolling for a period of time, may further include the following steps:

[0132] S41. Listen for scrolling events.

[0133] You can listen to scroll events through the addEventListener method of JavaScript. The object of listening is the scroll container of the page, such as the window object or a specific div element.

[0134] For example, you can use the addEventListener method to add a scroll event listener to the scroll container.

[0135] const container=document.querySelector('.scroll-container');

[0136] container.addEventListener('scroll', handleScroll).

[0137] S42: Record the scrolling time.

[0138] In the callback function of the scroll event, record the current scroll time. This can be achieved by obtaining the current timestamp (Date.now()).

[0139] In the handleScroll function, use Date.now() to get the current timestamp and save it to a variable. For example, you can use the following code to implement it:

[0140] let lastScrollTime = 0;

[0141] function handleScroll(){

[0142] const now = Date.now();

[0143] / / ...other logic

[0144] }

[0145] S43. Compare the time difference.

[0146] Compare the current scrolling time with the time of the last scrolling event record. This time difference can be used as a threshold to determine whether the user has stopped scrolling.

[0147] In the handleScroll function, compare the time difference between the current time and the last scroll time. For example, you can use the following code to implement it:

[0148] if(now-lastScrollTime>THRESHOLD){

[0149] / / The user has stopped scrolling, perform loading or rendering operations

[0150] lastScrollTime = now;

[0151] loadMoreData();

[0152] }

[0153] S44: Execute a loading or rendering operation.

[0154] If the user has stopped scrolling for more than the set time threshold, you can use AJAX or Fetch API to perform data block loading or rendering operations. Send a request to the server, get the new data block, and update the list on the page.

[0155] By adopting step S4, the purpose of throttling is achieved by limiting the processing frequency of scrolling events, thereby avoiding excessive triggering of rendering operations. Data loading or rendering is performed after the user stops scrolling for a period of time, reducing unnecessary calculations and having an anti-shake effect.

[0156] Step S5, start multi-threading in the background to process the background data, and parse, filter and sort the background data.

[0157] Backend data covers many aspects, including but not limited to user data, transaction data, log data, etc. Specifically for e-commerce systems, backend data may include product information, order data, user behavior data, etc.

[0158] In this embodiment, step S5, starting multi-threading in the background to process background data, parsing, filtering and sorting the background data may specifically include the following steps:

[0159] S51, data reception: the background service receives data from the database.

[0160] The backend service may also receive data from other data sources. At this stage, the integrity and accuracy of the data need to be ensured.

[0161] S52. Multi-thread allocation: Based on the type and amount of data, the background service dynamically allocates multiple threads for parallel processing.

[0162] The implementation of background multi-threaded data processing depends on the specific programming language and framework. For example, in Java, you can use thread pools to implement multi-threaded processing; in Python, you can use multi-threaded libraries to implement it.

[0163] Multithreaded parallel processing can significantly increase the speed of data processing, thereby shortening user waiting time and improving user experience. By dynamically allocating threads, system resources can be fully utilized to avoid resource waste. Multithreaded processing can decompose complex tasks into multiple simple subtasks, thereby reducing the complexity of a single task and improving system stability and reliability. This processing method can significantly increase the speed and efficiency of data processing.

[0164] S53, data analysis: Each thread analyzes the assigned data and converts it into a data structure suitable for processing.

[0165] For example, parse JSON formatted data into an object or array.

[0166] S54, Data filtering: Filter the data according to the needs of the front end.

[0167] For example, select only data within a certain time range, or only data that meets certain conditions.

[0168] S55. Data sorting: Sort the filtered data to meet the needs of front-end list rendering.

[0169] The choice of sorting algorithm should be determined based on the size and characteristics of the data.

[0170] S56, Data formatting: Format the sorted data into a format that the front end can recognize, such as a JSON string. At the same time, the data can also be compressed at this stage to reduce network transmission overhead.

[0171] S57, data return: return the formatted data to the front-end service.

[0172] At this stage, you need to ensure the accuracy and completeness of the data and deal with issues such as network errors or timeouts that may occur.

[0173] By adopting step S5, main thread blocking can be avoided. In the front-end and back-end interaction scenario, front-end list rendering and back-end data processing are two complementary links. Especially when processing large amounts of data, the introduction of back-end multi-threaded processing technology can significantly improve data processing efficiency and provide faster and more accurate data support for the front end.

[0174] Step S6, minimizing the number of DOM operations and using CSS transformation and animation to move and hide list items.

[0175] In this embodiment, step S6, minimizing the number of DOM operations and using CSS transformation and animation to move and hide list items may further include the following steps:

[0176] S61. Use Vue.js's virtual DOM and Diff algorithm to minimize the number of DOM operations.

[0177] Vue.js minimizes the number of DOM operations through virtual DOM and efficient Diff algorithm. When the data changes, Vue creates a new virtual DOM tree and compares it with the old virtual DOM tree. After finding the difference, only the part of the actual DOM that needs to be changed is updated. This strategy can greatly improve performance.

[0178] S62. Optimize the list.

[0179] When rendering a list using the v-for directive, provide each list item with a unique key attribute. This helps Vue track the identity of each node, allowing it to reuse and reorder existing elements instead of re-rendering the entire list.

[0180] S63. Add CSS styles and use CSS transitions.

[0181] Add necessary CSS styles for list items, including transitions and keyframe animations. These styles should be defined in the global style sheet or in the component's <style>标签中。

[0182] CSS过渡可以平滑地改变一个CSS属性的值。在列表项移动或隐藏时,可以使用过渡来创建平滑的动画效果。例如,使用transition属性设置元素的位置、透明度等属性的过渡效果。

[0183] S64、触发CSS动画。

[0184] 当数据发生变化时,Vue.js自动触发DOM更新。可以利用Vue的生命周期钩子或计算属性来监听数据变化,并在适当的时候触发CSS动画。

[0185] 对于更复杂的动画效果,可以使用CSS关键帧动画。通过定义@keyframes规则,可以指定动画在不同时间点的样式,从而创建复杂的动画序列。这可以用于实现列表项的复杂移动和隐藏效果。

[0186] 通过采用步骤S6,通过合理的DOM结构设计和内存回收策略,减少内存占用,对内存进行优化;最小化DOM操作次数,能够减少DOM操作;可以提高前端列表渲染的性能和用户体验;不仅可以减少浏览器的重绘和重排次数,还可以为用户呈现更加流畅和自然的动画效果。

[0187] 在本实施例的一些可选的实现方式中,在步骤S6之后,上述电子设备还可以执行以下步骤:

[0188] S7、将服务端渲染与客户端渲染相结合。

[0189] 具体实施时,步骤S7还可以包括步骤:

[0190] S71,在服务端预先渲染部分列表项。

[0191] 服务端预先渲染部分列表项是指在用户首次请求页面时,服务器根据数据和模板生成一部分HTML列表项,并将其发送给客户端。

[0192] 数据准备:服务器根据请求参数从数据库中获取列表数据。

[0193] 模板渲染:服务器使用模板引擎(如Pug、EJS等)将数据和HTML模板结合,生成部分列表项的HTML字符串。

[0194] 响应发送:服务器将生成的HTML字符串作为响应发送给客户端。

[0195] 由于部分列表项已经在服务端渲染完成,客户端无需等待JavaScript执行即可完成页面渲染,从而提高了首屏加载速度;服务端渲染的HTML页面包含了部分列表项的内容,有利于搜索引擎的抓取和索引。

[0196] 这样对服务器端进行渲染,能加快首屏加载速度。

[0197] S72、在客户端根据用户行为动态渲染剩余列表项。

[0198] 在客户端接收到服务端渲染的HTML页面后,JavaScript代码会根据用户行为(如滚动、点击等)动态加载并渲染剩余的列表项。这一步骤的实现主要依赖于JavaScript的异步加载和数据驱动视图框架(如React、Vue等)。

[0199] 监听事件:JavaScript代码监听页面滚动、点击等事件。

[0200] 异步加载数据:当用户行为触发时,JavaScript代码通过Ajax或Fetch等技术从服务器异步加载剩余列表项的数据。

[0201] 动态渲染:JavaScript代码使用数据驱动视图框架将加载的数据转换为HTML字符串,并将其插入到页面中相应的位置。

[0202] 通过异步加载和动态渲染,用户可以在不刷新页面的情况下加载更多内容,提高了用户体验;由于大部分渲染工作都在客户端完成,服务器只需处理数据请求和响应,从而减轻了服务器压力;客户端渲染可以实现复杂的用户交互和实时更新,满足了高交互性应用的需求。

[0203] 在本实施例的一些可选的实现方式中,在步骤S6之后,上述电子设备还可以执行以下步骤:

[0204] S8,利用浏览器缓存、本地存储方式缓存已加载的数据。

[0205] 已加载的数据指的是在前端应用程序运行过程中,已经从服务器获取并渲染到页面上的数据。这些数据可能包括用户信息、商品列表、文章内容等,它们通常以数组、对象等数据结构形式存在。

[0206] 浏览器缓存是一种基于HTTP协议的缓存机制,用于存储网页资源(如HTML、CSS、JavaScript文件、图像等)。当用户再次访问同一页面时,浏览器会优先从缓存中加载这些资源,从而减少了网络传输时间,提升了页面加载速度。

[0207] 在列表渲染中,可以利用浏览器缓存来缓存已加载的列表数据。具体实现方式如下:

[0208] 在服务器端设置缓存头。例如,通过设置Cache-Control和ETag等HTTP头部字段,可以控制浏览器对资源的缓存行为。

[0209] 在前端发送请求时,浏览器会根据缓存头中的信息判断是否需要从服务器获取新数据。如果资源在缓存中且未过期,浏览器将直接从缓存中加载数据;否则,将向服务器发送请求。

[0210] 通过利用浏览器缓存,可以减少不必要的网络请求,降低服务器的负载,提高页面加载速度。同时,对于已缓存的数据,用户可以在离线状态下继续访问,提升了用户体验。

[0211] 除了浏览器缓存外,前端开发者还可以利用本地存储方式来缓存已加载的列表数据。本地存储方式包括LocalStorage、SessionStorage等。

[0212] 以LocalStorage为例,其是一种持久化的本地存储方式,数据会一直存在,直到被主动删除。在列表渲染中,可以将已加载的列表数据存储在LocalStorage中,并在需要时从LocalStorage中获取数据。具体实现方式如下:

[0213] 在加载列表数据时,将数据存储到LocalStorage中。可以使用localStorage.setItem(key,value)方法将数据以键值对的形式存储到LocalStorage中。

[0214] 在需要渲染列表时,首先从LocalStorage中获取数据。可以使用localStorage.getItem(key)方法获取指定键的数据。

[0215] 通过利用本地存储方式,可以实现数据的持久化存储,并在需要时快速获取数据,减少了网络请求和服务器负载。同时,对于已存储的数据,用户可以在不同的浏览器窗口或标签页中共享,进一步提升了用户体验。

[0216] 通过步骤S8,可以减少重复请求,也能够确保客户端和服务器端的数据同步,同步处理数据更新,避免数据冲突。

[0217] 在本实施例的一些可选的实现方式中,在步骤S6之后,上述电子设备还可以执行以下步骤:

[0218] S9,根据具体需求配置渲染参数、插件和钩子,渲染参数包括每块的数据量、预加载策略。

[0219] 根据每块的数据量设置渲染参数,这是分批渲染(或增量渲染)的基础。通过将大量数据分块处理,可以避免一次性渲染所有数据导致的页面卡顿。

[0220] 预加载策略是另一个关键步骤。它通过在用户需要前预先加载数据,减少了数据请求的时间,从而提升了页面的响应速度。预加载策略通常根据用户的操作习惯或页面的滚动位置来触发。

[0221] 具体实施时,可以使用JavaScript的异步API(如

[0222] requestAnimationFrame或setTimeout)来分批加载数据,并结合浏览器的Intersection Observer API来检测页面的滚动位置,以决定何时触发预加载。

[0223] 通过步骤S9,使得本实施例可配置性强,允许开发者自定义进行渲染参数配置,开发自由度高;通过设计灵活的插件和钩子机制,支持开发者扩展新功能;能够显著提高页面的加载速度和响应性,从而提升用户体验;通过合理设置渲染参数和预加载策略,还可以有效减轻服务器的压力,提高整体系统的性能。

[0224] 在本实施例的一些可选的实现方式中,在步骤S6之后,上述电子设备还可以执行以下步骤:

[0225] S10,进行渲染兼容性测试,通过自动化测试和性能监控,优化渲染性能。

[0226] 例如使用Jest、Mocha等测试框架,可以编写针对各种设备和浏览器的测试用例,确保列表渲染在不同环境下都能正确工作,通过自动化测试来确保渲染的正确性和兼容性。

[0227] 性能监控是优化渲染性能的关键。通过收集和分析页面加载时间、渲染时长等性能指标,可以发现性能瓶颈并进行针对性优化。

[0228] 在优化方面,可以采用虚拟滚动、分页加载等技术来减少一次性渲染的数据量,降低DOM操作的复杂性。此外,还可以使用Web Workers进行异步数据处理,避免阻塞主线程,也能显著提升渲染性能。

[0229] 进行渲染兼容性测试的目的在于确保渲染方案在不同浏览器和设备上均能正常工作。

[0230] 实施本实施例,其有益效果是:通过虚拟滚动和其他优化技术,显著减少了DOM操作和重绘 / 重排次数,从而提升了页面的渲染性能;避免了一次性加载和渲染所有列表项,有效降低了内存占用,减少了因内存不足导致的性能问题或应用崩溃;实现了平滑的滚动体验,无明显卡顿或延迟,即使在数据量巨大的情况下也能保持流畅的交互,改善了用户体验;通过延迟加载和智能预加载技术,加快了数据的响应速度,用户可以更快地看到需要的信息,响应速度加快;设计灵活,易于扩展,可以适应不同规模的数据集和多样化的业务需求,可扩展性强;兼容主流浏览器和设备,确保了广泛的用户覆盖和一致的体验,兼容性强;组件化设计和状态管理的使用,使得代码更加模块化,易于开发和维护;通过服务端和客户端的数据一致性检查,确保了显示的数据是准确和最新的,数据的准确性有保障;开发者可以根据具体需求调整数据块的大小、加载策略等参数,实现定制化的渲染效果,灵活性强;通过减少一次性请求大量数据的情况,减轻了服务器的负担,提高了服务的稳定性和扩展性,减轻服务器负担;统一的渲染方案和工具库使得开发者能够快速实现长列表功能,加快开发速度,提高开发效率。

[0231] 本发明可用于众多通用或专用的计算机系统环境或配置中。例如:个人计算机、服务器计算机、手持设备或便携式设备、平板型设备、多处理器系统、基于微处理器的系统、置顶盒、可编程的消费电子设备、网络PC、小型计算机、大型计算机、包括以上任何系统或设备的分布式计算环境等等。本发明可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本发明,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。

[0232] 本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,该计算机可读指令可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random Access Memory,RAM)等。

[0233] 应该理解的是,虽然附图的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,其可以以其他的顺序执行。而且,附图的流程图中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,其执行顺序也不必然是依次进行,而是可以与其他步骤或者其他步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。

[0234] 实施例二

[0235] 为了具体展示本发明的前端列表渲染方法,以下以电子商务网站商品列表页面渲染为例进行说明:

[0236] 场景描述:假设一个电商平台需要展示成千上万的商品信息,每个商品信息包括图片、名称、价格和简介。用户可以通过滚动页面来浏览所有商品。

[0237] 以下为本实施例的一种前端列表渲染方法实施步骤:

[0238] S21、定义数据块大小,向后端发送数据请求以获取数据库。

[0239] 定义数据块大小:根据页面可视区域和商品列表项的高度,确定每屏可显示的商品数量,进而确定每块数据包含的商品数。

[0240] 请求数据:当用户滚动到页面底部时,向后端发送请求,获取下一批数据块。

[0241] S22、计算滚动位置,动态渲染列表项,进行虚拟滚动。

[0242] 计算滚动位置:监听滚动事件,实时计算当前滚动位置。

[0243] 动态渲染列表项:根据滚动位置,动态计算并渲染当前可视区域内的商品信息。

[0244] S23、进行组件化设计。

[0245] 创建商品组件:为每个商品信息创建一个React组件,包含商品的图片、名称、价格和简介。

[0246] 列表项渲染:使用组件化的商品组件填充虚拟滚动容器。

[0247] S24、进行商品列表状态管理。

[0248] 使用Redux管理状态:使用Redux等状态管理库来管理商品列表的状态,包括已加载的数据块和滚动位置。

[0249] 响应状态变化:当商品列表的状态更新时,触发列表项的重新渲染。

[0250] S25、进行滚动节流和加载防抖。

[0251] 节流滚动事件:对滚动事件使用节流技术,限制滚动处理函数的执行频率。

[0252] 防抖加载数据:在用户停止滚动一定时间后,再触发数据加载。

[0253] S26、进行Web Workers数据处理。

[0254] 使用Web Workers:将数据处理逻辑(如搜索、过滤)放在Web Workers中执行。

[0255] 数据返回主线程:处理完成后,将经过Web Workers进行数据处理的结果返回到主线程进行渲染。

[0256] S27、进行内存优化。

[0257] 合理回收内存:对于已经离开可视区域的商品组件,进行适当的内存回收操作。

[0258] 避免内存泄漏:确保组件卸载时,清除所有事件监听器和定时器。

[0259] S28、将服务端渲染与客户端渲染结合。

[0260] 首屏服务端渲染:首屏商品列表由服务端渲染,快速展示给用户。

[0261] 后续客户端渲染:用户滚动加载更多商品时,由客户端进行渲染。

[0262] S29、设置缓存策略。

[0263] 使用本地存储:将已加载的商品数据缓存到本地存储中。

[0264] 数据一致性检查:在渲染前检查缓存数据的时效性,必要时重新请求数据。

[0265] S30、进行渲染性能测试与优化。

[0266] 性能监控:使用性能监控工具,如Chrome DevTools,监控渲染性能。

[0267] 优化迭代:根据性能数据,不断调整和优化实现方案。

[0268] 通过上述实施本实施例,电商平台的商品列表页面实现了快速加载、流畅滚动和高效渲染,极大提升了用户体验。同时,通过组件化和状态管理,代码的可维护性和扩展性也得到了增强。

[0269] 实施例三

[0270] 进一步参考图2,作为对上述图1所示方法的实现,本发明提供了一种前端列表渲染装置的一个实施例,该装置实施例与图1所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。

[0271] 如图2所示,本实施例前端列表渲染装置70包括:预加载模块71、加载模块72、管理模块73、限制模块74、处理模块75以及优化模块76。其中:

[0272] 预加载模块71,用于获取列表数据,将列表数据分割成多个数据块,仅渲染可视区域内的多个数据块,预加载即将进入可视区域的多个数据块;

[0273] 加载模块72,用于根据用户的滚动行为,动态加载多个数据块,预测用户的滚动方向和速度,提前加载将需要加载的多个数据块;

[0274] 管理模块73,用于将每个列表项封装为独立的组件,使用状态管理库来维护和管理列表的状态;

[0275] 限制模块74,用于限制滚动事件的处理频率,在用户停止滚动一段时间后,再进行数据块的加载或渲染;

[0276] 处理模块75,用于在后台开启多线程处理数据,对数据进行解析、过滤和排序;

[0277] 优化模块76,用于最小化DOM操作次数,利用CSS变换和动画来实现列表项的移动和隐藏。

[0278] 实施本实施例,其有益效果是:通过虚拟滚动和其他优化技术,显著减少了DOM操作和重绘 / 重排次数,从而提升了页面的渲染性能;避免了一次性加载和渲染所有列表项,有效降低了内存占用,减少了因内存不足导致的性能问题或应用崩溃;实现了平滑的滚动体验,无明显卡顿或延迟,即使在数据量巨大的情况下也能保持流畅的交互,改善了用户体验;通过延迟加载和智能预加载技术,加快了数据的响应速度,用户可以更快地看到需要的信息,响应速度加快;设计灵活,易于扩展,可以适应不同规模的数据集和多样化的业务需求,可扩展性强;兼容主流浏览器和设备,确保了广泛的用户覆盖和一致的体验,兼容性强;组件化设计和状态管理的使用,使得代码更加模块化,易于开发和维护;通过服务端和客户端的数据一致性检查,确保了显示的数据是准确和最新的,数据的准确性有保障;开发者可以根据具体需求调整数据块的大小、加载策略等参数,实现定制化的渲染效果,灵活性强;通过减少一次性请求大量数据的情况,减轻了服务器的负担,提高了服务的稳定性和扩展性,减轻服务器负担;统一的渲染方案和工具库使得开发者能够快速实现长列表功能,加快开发速度,提高开发效率。

[0279] 实施例四

[0280] 为解决上述技术问题,本发明实施例还提供计算机设备。具体请参阅图3,图3为本实施例计算机设备基本结构框图。

[0281] 上述计算机设备8包括通过系统总线相互通信连接存储器81、处理器82、网络接口83。需要指出的是,图中仅示出了具有组件存储器81、处理器82和网络接口83的计算机设备8,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。其中,本技术领域技术人员可以理解,这里的计算机设备是一种能够按照事先设定或存储的指令,自动进行数值计算和 / 或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable Gate Array,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。

[0282] 上述计算机设备可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。上述计算机设备可以与用户通过键盘、鼠标、遥控器、触摸板或声控设备等方式进行人机交互。

[0283] 上述存储器81至少包括一种类型的可读存储介质,上述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,上述存储器81可以是上述计算机设备8的内部存储单元,例如该计算机设备8的硬盘或内存。在另一些实施例中,上述存储器81也可以是上述计算机设备8的外部存储设备,例如该计算机设备8上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(FlashCard)等。当然,上述存储器81还可以既包括上述计算机设备8的内部存储单元也包括其外部存储设备。本实施例中,上述存储器81通常用于存储安装于上述计算机设备8的操作系统和各类应用软件,例如前端列表渲染方法的计算机可读指令等。此外,上述存储器81还可以用于暂时地存储已经输出或者将要输出的各类数据。

[0284] 上述处理器82在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器82通常用于控制上述计算机设备8的总体操作。本实施例中,上述处理器82用于运行上述存储器81中存储的计算机可读指令或者处理数据,例如运行上述前端列表渲染方法的计算机可读指令。

[0285] 上述网络接口83可包括无线网络接口或有线网络接口,该网络接口83通常用于在上述计算机设备8与其他电子设备之间建立通信连接。

[0286] 实施本实施例,其有益效果是:通过虚拟滚动和其他优化技术,显著减少了DOM操作和重绘 / 重排次数,从而提升了页面的渲染性能;避免了一次性加载和渲染所有列表项,有效降低了内存占用,减少了因内存不足导致的性能问题或应用崩溃;实现了平滑的滚动体验,无明显卡顿或延迟,即使在数据量巨大的情况下也能保持流畅的交互,改善了用户体验;通过延迟加载和智能预加载技术,加快了数据的响应速度,用户可以更快地看到需要的信息,响应速度加快;设计灵活,易于扩展,可以适应不同规模的数据集和多样化的业务需求,可扩展性强;兼容主流浏览器和设备,确保了广泛的用户覆盖和一致的体验,兼容性强;组件化设计和状态管理的使用,使得代码更加模块化,易于开发和维护;通过服务端和客户端的数据一致性检查,确保了显示的数据是准确和最新的,数据的准确性有保障;开发者可以根据具体需求调整数据块的大小、加载策略等参数,实现定制化的渲染效果,灵活性强;通过减少一次性请求大量数据的情况,减轻了服务器的负担,提高了服务的稳定性和扩展性,减轻服务器负担;统一的渲染方案和工具库使得开发者能够快速实现长列表功能,加快开发速度,提高开发效率。

[0287] 实施例五

[0288] 本发明还提供了另一种实施方式,即提供一种计算机可读存储介质,计算机可读存储介质存储有计算机可读指令,计算机可读指令可被至少一个处理器执行,以使至少一个处理器执行如上述的前端列表渲染方法的步骤。

[0289] 实施本实施例,其有益效果是:通过虚拟滚动和其他优化技术,显著减少了DOM操作和重绘 / 重排次数,从而提升了页面的渲染性能;避免了一次性加载和渲染所有列表项,有效降低了内存占用,减少了因内存不足导致的性能问题或应用崩溃;实现了平滑的滚动体验,无明显卡顿或延迟,即使在数据量巨大的情况下也能保持流畅的交互,改善了用户体验;通过延迟加载和智能预加载技术,加快了数据的响应速度,用户可以更快地看到需要的信息,响应速度加快;设计灵活,易于扩展,可以适应不同规模的数据集和多样化的业务需求,可扩展性强;兼容主流浏览器和设备,确保了广泛的用户覆盖和一致的体验,兼容性强;组件化设计和状态管理的使用,使得代码更加模块化,易于开发和维护;通过服务端和客户端的数据一致性检查,确保了显示的数据是准确和最新的,数据的准确性有保障;开发者可以根据具体需求调整数据块的大小、加载策略等参数,实现定制化的渲染效果,灵活性强;通过减少一次性请求大量数据的情况,减轻了服务器的负担,提高了服务的稳定性和扩展性,减轻服务器负担;统一的渲染方案和工具库使得开发者能够快速实现长列表功能,加快开发速度,提高开发效率。

[0290] 通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM / RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本发明各个实施例方法。

[0291] 显然,以上所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例,附图中给出了本发明的较佳实施例,但并不限制本发明的专利范围。本发明可以以许多不同的形式来实现,相反地,提供这些实施例的目的是使对本发明的公开内容的理解更加透彻全面。尽管参照前述实施例对本发明进行了详细的说明,对于本领域的技术人员来而言,其依然可以对前述各具体实施方式所记载的技术方案进行修改,或者对其中部分技术特征进行等效替换。凡是利用本发明说明书及附图内容所做的等效结构,直接或间接运用在其他相关的技术领域,均同理在本发明专利保护范围之内。< / style>

Claims

1. A front-end list rendering method, characterized in that: The steps include: Acquire list data, divide the list data into multiple data blocks, render only the multiple data blocks in the visible area, and preload the multiple data blocks that are about to enter the visible area; According to the user's scrolling behavior, dynamically load multiple data blocks, predict the user's scrolling direction and speed, and load multiple data blocks that will be loaded in advance; Encapsulate each list item as an independent component and use the state management library to maintain and manage the state of the list; Limit the processing frequency of scrolling events, and load or render the data block after the user stops scrolling for a period of time; Start multi-threaded data processing in the background to parse, filter and sort the data; Minimize the number of DOM operations and use CSS transformations and animations to move and hide list items.

2. The front-end list rendering method according to claim 1, characterized in that: The steps of obtaining list data, dividing the list data into a plurality of data blocks, rendering only the plurality of data blocks in the visible area, and preloading the plurality of data blocks that are about to enter the visible area specifically include: Get list data from the backend or local storage through API requests; According to the height of the list items and the height of the visible area, the list data is divided into multiple data blocks, and the number of list items contained in each data block is determined; By listening to scroll events and calculating the scroll position, only multiple data blocks within the visible area are rendered; Preload multiple chunks of data that are about to enter the viewport.

3. The front-end list rendering method according to claim 1, characterized in that: The step of dynamically loading the plurality of data blocks according to the user's scrolling behavior, predicting the user's scrolling direction and speed, and loading the plurality of data blocks that will be loaded in advance specifically includes: Dynamically load multiple data blocks based on the user's scrolling behavior; Predict the user's scrolling direction and speed, and load the data blocks that will be loaded in advance.

4. The front-end list rendering method according to claim 1, characterized in that: The steps of encapsulating each list item as an independent component and using the state management library to maintain and manage the state of the list specifically include: Define the list data structure; Create a list item component; Use the v-for directive to render the list; Add a unique identifier key; Introducing a state management library; Define list states in the state management library; Use state management libraries in components; Encapsulation and reuse.

5. The front-end list rendering method according to claim 1, characterized in that: The step of limiting the processing frequency of the scrolling event and then loading or rendering the data block after the user stops scrolling for a period of time specifically includes: Listen for scroll events; Record the scrolling time; Compare time differences; Perform a load or render operation.

6. The front-end list rendering method according to claim 1, characterized in that: The steps of starting multi-threaded data processing in the background and parsing, filtering and sorting the data specifically include: Data reception: The background service receives data from the database; Multi-thread allocation: Based on the type and amount of data, the background service dynamically allocates multiple threads for parallel processing; Data parsing: Each thread parses the assigned data and converts it into a data structure suitable for processing; Data filtering: filter data according to the needs of the front end; Data sorting: Sort the filtered data; Data formatting: Format the sorted data into a format that can be recognized by the front end; Data return: Return the formatted data to the front-end service.

7. The front-end list rendering method according to any one of claims 1 to 6, characterized in that: The step of minimizing the number of DOM operations and using CSS transformation and animation to move and hide list items specifically includes: Use Vue.js's virtual DOM and Diff algorithm to minimize the number of DOM operations; Optimize the list; Add CSS styles and use CSS transitions; Trigger a CSS animation.

8. A front-end list rendering device, characterized in that: include: A preloading module, used for acquiring list data, dividing the list data into multiple data blocks, rendering only the multiple data blocks in the visible area, and preloading the multiple data blocks that are about to enter the visible area; A loading module, used to dynamically load the plurality of data blocks according to the user's scrolling behavior, predict the user's scrolling direction and speed, and load the plurality of data blocks that will be loaded in advance; The management module is used to encapsulate each list item as an independent component and use the state management library to maintain and manage the state of the list; A limiting module, used to limit the processing frequency of scrolling events, and to load or render the data block after the user stops scrolling for a period of time; The processing module is used to start multi-threaded data processing in the background to parse, filter and sort the data; An optimization module that minimizes the number of DOM operations and uses CSS transformations and animations to move and hide list items.

9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the front-end list rendering method according to any one of claims 1 to 7 when executing the computer-readable instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the front-end list rendering method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Rendering method, chip, electronic equipment and storage medium

    CN116738089A

  • Page rendering method and device, electronic equipment and storage medium

    CN117668390A

  • Method and device for realizing Table cascade scrolling based on dom simulation

    CN118244957A

  • Automated subscriber document directory system

    US20020019842A1

  • System and method for managing a scalable list of items for display

    US6959425B1

Cited By

  • Page picture resource progressive loading method, device and system and storage medium

    CN119669595A

  • Page rendering method and device, equipment and storage medium

    CN120429517A

  • Simulator starting acceleration method and device, equipment and storage medium

    CN120492053A

  • Dynamic data loading and rendering method and system based on Luckysheet

    CN120723330A

  • List content rendering method and device of embedded device and storage medium

    CN121478399A