A table height self-adapting method and system based on a Vue custom directive
By using Vue custom directive binding and instance-level adaptive context management, the adaptive problem of table components under dynamic layout and nested containers is solved, realizing height adaptation of table components under different vertical display boundaries and reducing repeated layout updates.
Patent Information
- Application Number
- CN202611333225.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-20
AI Technical Summary
In web management systems, data analysis platforms, and business applications, table components struggle to adapt to vertical display boundaries in dynamic layouts and nested container scenarios, leading to frequent scrolling and layout updates, a problem that existing technologies cannot effectively solve.
By adopting a Vue custom directive-based approach, we can establish an instance-level adaptive context by binding custom directives, listen for page size changes, merge height update requests, obtain the geometric parameters of the browser viewport and the restricted parent container, calculate and apply the target height, recalculate the component layout, and reduce redundant updates.
It enables adaptive height adjustment of the table component under dynamic layout and nested containers, reduces height deviation and repeated layout updates caused by mixed coordinate references, and improves user experience.
Smart Images

Figure CN123138535A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of web front-end page layout technology, specifically to a method and system for adaptive table height based on Vue custom directives. Background Technology
[0002] In web management systems, data analytics platforms, and business applications, table components are commonly used to display structured data with multiple rows and columns. When a large number of data rows are displayed at once and the table height is not limited, the table content will continuously expand the page and form a long vertical scrolling area, requiring users to frequently scroll between the query area at the top of the page, the operation area, and the bottom of the table.
[0003] Existing solutions mainly include limiting the number of rows displayed in a table at one time and using a pagination tool, or setting a fixed pixel height for the table. The former requires determining the single-page capacity based on the page layout and table row height, while the latter is difficult to adjust to changes in browser window size, display resolution, page area visibility, and container size, which can easily result in tables exceeding the available display area or leaving large blank spaces below the table.
[0004] Some dynamic height handling methods recalculate the table height based on the browser viewport height and the table's top position. However, in nested layouts such as pop-ups, drawers, and tab content areas, the parent container that actually forms the vertical display boundary may also limit the table's available space. If the parent container height and the table's position relative to the browser viewport are directly mixed, it can easily lead to inconsistent coordinate references. Continuous size changes may also frequently trigger geometric parameter readings and component layout updates.
[0005] Therefore, a table height adaptive solution is needed that can adapt to different vertical display boundaries in dynamic layout and nested container scenarios, determine the available vertical height of the table, and reduce repeated layout updates. Summary of the Invention
[0006] The purpose of this invention is to provide a method and system for adaptive table height based on Vue custom directives, so as to determine the vertical available height of the target table component and update the internal layout of the component in scenarios where the browser viewport and the nested restricted parent container may jointly form a vertical display boundary.
[0007] To achieve the above objectives, the present invention adopts the following technical solution.
[0008] In a first aspect, the present invention provides a method for adaptive table height based on Vue custom directives, comprising the following steps: Step S101: Bind a custom instruction, establish an instance-level adaptive context, and register a page size change listener. Bind the custom instruction to a target table component that has a component height setting interface and a component layout recalculation interface, obtain the component instance of the target table component and the instruction parameters including the bottom allowance, establish an instance-level adaptive context associated with the target table component, and register a page size change listener; Step S102: In response to component insertion or size change notifications, submit and merge height update requests. A height update request is submitted when the target table component is inserted into the page or when any registered size change listener outputs a size change notification. Multiple height update requests submitted consecutively within a preset event merging delay time are merged into a single height update task to be executed. Step S103: Perform a height update task, determine reference display areas, and obtain geometric parameters under the coordinate reference corresponding to each reference display area. When performing the height update task, determine the target table element corresponding to the target table component in the document object model, and determine the browser viewport as the first reference display area; when a restricted parent container located on the ancestor node chain of the target table element forms a vertical display boundary for the target table element, determine the restricted parent container as the second reference display area; if no container size change listener has been registered for the restricted parent container, register a container size change listener for it; for each reference display area, under the coordinate reference corresponding to the reference display area, obtain the visible height of the reference display area and the position of the top of the target table element relative to the top of the reference display area. Step S104: Calculate candidate heights, verify constraint validity, and determine the target height. Based on the visible height of each reference display area, the position of the top of the target table element relative to the top of that reference display area, and the bottom allowance, calculate the corresponding candidate height. When only the first reference display area exists, determine the target height based on a finite first candidate height that is greater than zero. When a second reference display area exists, determine the target height based on the smaller of the first and second candidate heights only if both are finite values greater than zero. Terminate the height update task if any candidate height involved in the calculation is less than or equal to zero or is not a finite value. Step S105: Apply the target height and recalculate the internal layout of the target table component. The target height is applied through the component height setting interface of the target table component, and the component layout recalculation interface is called to recalculate the internal layout of the target table component according to the target height. Simultaneously, the target height is recorded as the new currently effective height.
[0009] Furthermore, the custom instruction includes a binding hook, an insertion hook, and an unbinding hook; the binding hook is used to establish an instance-level adaptive context and register a page size change listener, and the insertion hook is used to submit the first height update request; after determining the second reference display area, a container size change listener is registered for the corresponding restricted parent container, and the container size change listener is switched when the restricted parent container changes; when the custom instruction is unbound from the target table component, the registered size change listener is removed, the unbinding hook is used to cancel the height update task that has not yet been executed, and the instance-level adaptive context is released; different target table components in the same page maintain mutually isolated instance-level adaptive contexts respectively.
[0010] Furthermore, the restricted parent container can be determined based on the container specified by the instruction parameter that is located on the ancestor node chain of the target table element and forms a vertical display boundary; if no restricted parent container is specified or the specified container does not meet the aforementioned conditions, an ancestor container that forms a vertical clipping boundary or a scroll boundary is searched along the ancestor node chain of the target table element, and the candidate container closest to the target table element is determined as the restricted parent container.
[0011] Furthermore, the first candidate height corresponding to the first reference display area according to Determined; when the second reference display area exists, the second candidate height corresponding to the second reference display area. according to Determined; among them, and Use the coordinate reference corresponding to the browser viewport. and Use the coordinate reference corresponding to the content area of the restricted parent container. This refers to the same bottom allowance used in the calculation of both candidate heights.
[0012] Furthermore, when the second reference display area does not exist, the first candidate height, which is greater than zero and has a finite value, is selected. Height determined to be corrected When the second reference display area exists, only at the first candidate height. Second candidate height When both are finite values greater than zero, the smaller value is determined as the height to be corrected. .
[0013] Furthermore, the target height according to It is confirmed that, among them, The preset maximum height ratio is greater than zero and not greater than 1; when the second reference display area does not exist, The visible height of the first reference display area When the second reference display area exists, for The visible height of the second reference display area The smaller value in the range.
[0014] Furthermore, each time a new height update request is received, the height update task that has not yet been executed is cancelled, and the height update task is recreated according to the preset event merging delay duration; when the current effective height has not been recorded or the absolute difference between the target height and the current effective height is greater than the preset height difference threshold, the target height application and component layout recalculation are executed; during the target height writing, the height application state is set to suppress the feedback size change notification caused by this target height writing and component layout recalculation.
[0015] Furthermore, the target table component can be the el-table component provided by Element UI, the component height setting interface can be the setHeight method provided by the el-table component layout object, and the component layout recalculation interface can be the doLayout method provided by the el-table component, and the doLayout method is called after the Vue view is updated.
[0016] Furthermore, in the Vue 3 runtime environment, the binding, insertion, and unbinding phases of the custom directive can be implemented through the beforeMount, mounted, and unmounted hooks, respectively. The target table component can be a table component provided by ElementPlus, and the above method can be implemented through the corresponding interface with height setting and layout recalculation functions.
[0017] Secondly, this invention provides a table height adaptive system based on Vue custom directives, including a directive binding and context management module, a size change monitoring and update scheduling module, a geometric parameter acquisition and reference display area determination module, a candidate height calculation and validity verification module, a component height setting and layout update module, and a lifecycle cleanup module.
[0018] The instruction binding and context management module is used to establish an instance-level adaptive context; the size change listening and update scheduling module is used to register size change listeners, submit and merge height update requests; the geometric parameter acquisition and reference display area determination module is used to determine the reference display area corresponding to the browser viewport and the restricted parent container, and obtain the geometric parameters under the coordinate reference of each reference display area; the candidate height calculation and validity verification module is used to calculate and verify the candidate height, and determine the target height based on the more stringent valid candidate height; the component height setting and layout update module is used to apply the target height, perform internal layout recalculation of the component and write back the currently effective height; the lifecycle cleanup module is used to remove listeners, cancel pending tasks and release the instance-level adaptive context when the instruction is unbound.
[0019] Compared with the prior art, the present invention has at least the following beneficial effects: 1. Obtain the visible height and the top position of the target table element under the coordinate references corresponding to the browser viewport and the restricted parent container, respectively, and constrain the target height with multiple real vertical boundaries. This can reduce height deviations caused by mixing coordinate references, ignoring stricter boundaries, or incorrectly using another candidate height when there is no available space.
[0020] 2. By using instance-level adaptive context to isolate and manage page listeners, container listeners, pending tasks, and the current effective height, and by merging height update requests during continuous size changes, it can reduce duplicate measurements, invalid height writes, and feedback-based repeated triggers.
[0021] 3. By applying the target height through the component height setting interface and component layout recalculation interface provided by the target table component, the table header, table body, fixed columns and internal scrolling areas can be updated synchronously based on the target height; by releasing the listener, canceling the task and releasing the context during the unbinding phase, invalid callbacks after component destruction can be reduced. Attached Figure Description
[0022] Figure 1 This is a flowchart illustrating the table height adaptive method based on Vue custom directives of the present invention. Figure 2 This is a schematic diagram illustrating the geometric relationship between the browser viewport, the restricted parent container, and the target table component in this invention. Figure 3 This is a schematic diagram of the modules and data flow of the table height adaptive system based on Vue custom directives of the present invention. Detailed Implementation
[0023] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. It should be understood that the following embodiments are only used to illustrate the technical solutions of the present invention and do not constitute a limitation on the scope of protection of the present invention.
[0024] For ease of understanding, unless otherwise stated, the following terms have the following meanings in this specification: Document Object Model (DOM) refers to the object model used by the browser to represent and manipulate the structure of page nodes; Target table component refers to the table component that is the object bound to the custom instruction and has a component height setting interface and a component layout recalculation interface; Target table element refers to the element in the DOM corresponding to the target table component and pre-determined to obtain the boundary rectangle and top position, which in this embodiment is the root element of the table component bound to the custom instruction; Restricted parent container refers to the container located on the ancestor node chain of the target table element and forming the actual boundary of the vertical available display space of the target table component through vertical clipping, scrolling or other layout constraints; Reference display area refers to the area used to limit the vertical available display space of the target table component and serve as the basis for candidate height calculation; Instance-level adaptive context refers to the data set associated with a single target table component and used to store the instruction parameters, component interface references, listener references, task identifiers and height status of the target table component; Current effective height refers to the height value that was most recently applied to the target table component through the component height setting interface and recorded in the instance-level adaptive context.
[0025] This example uses the el-table component provided by Vue 2 and Element UI as an example, and the custom directive is named v-adaptive.
[0026] like Figure 1 As shown, the method in this embodiment includes steps S101 to S105.
[0027] Step S101: Bind custom instructions, establish instance-level adaptive context and register page size change listeners.
[0028] Register the `v-adaptive` custom directive in the Vue application entry point or business module, and bind the directive to the `el-table` component tag that needs to perform height adaptation. The directive binding value is in object form, which includes at least the bottom offset, and may also include optional component identifier `tableId`, restricted parent container identifier `containerSelector`, maximum height ratio `maxHeightRatio`, event merging delay `debounceDelay`, and height difference threshold `updateThreshold`.
[0029] The bottom margin is used to deduct the vertical space occupied by pagination, action bars, bottom margins, or other page elements from the available height of the browser viewport or restricted parent container. As an example, bottomOffset, maxHeightRatio, debounceDelay, and updateThreshold can be set to 70 pixels, 1, 100 milliseconds, and 5 pixels respectively, and these values can be adjusted according to the page layout.
[0030] The binding hook for custom directives obtains the target table component instance `$table` through the `componentInstance` property of the Vue virtual node, and associates and stores the directive parameters, component instance reference, current restricted parent container reference, current effective height, page size change listener reference, container size change listener reference, pending height update task identifier, and height application state with the target table element. Different target table components maintain their own instance-level adaptive contexts.
[0031] The instance-level adaptive context can be stored as a weakly mapped object with the target table element as the key, or associated with a preset attribute on the target table element. Regardless of the storage method used, the state is isolated at the individual target table component, without relying on page-level global component identifiers to share the listening state.
[0032] The hook invokes the element size listener provided by Element UI, using `window.document.body` as the listener object for page size changes, and binds the `handleResize` callback function using the `addResizeListener` method. The listener callback only submits a height update request; it does not directly read geometric parameters or perform component layout recalculation.
[0033] Step S102: In response to component insertion or size change notifications, submit and merge height update requests.
[0034] After the target table component is inserted into the page DOM, the insertion hook of the custom directive submits the first height update request. Before the first height update task is executed, registered size change listeners include page size change listeners; after determining the second reference display area in step S103 and registering a container size change listener for it, subsequent notifications output by the container size change listener also submit height update requests according to this step. In cases where the browser window is scaled up or down, the query area is expanded or collapsed, the sidebar is shown or hidden, the size of the pop-up or drawer changes, or other situations that cause changes in the vertical available display space, when any registered size change listener outputs a size change notification, a subsequent height update request is submitted. Each time a new height update request is received, the scheduled task that has not yet been executed is canceled, and the task is recreated according to debounceDelay; subsequent geometric parameter reading and height calculation are only executed if no new request is received within the corresponding time period.
[0035] Step S103: Perform a height update task, determine the reference display area, and obtain geometric parameters under the coordinate reference corresponding to each reference display area.
[0036] Get the visible height of the browser viewport using window.innerHeight or document.documentElement.clientHeight. The bounding rectangle of the target table element is obtained through the getBoundingClientRect method, and the top value of this bounding rectangle is used to determine the position of the top of the target table element relative to the top of the browser viewport. The browser viewport constitutes the first reference display area.
[0037] The restricted parent container can be specified by containerSelector, but the specified container should be located on the ancestor node chain of the target table element and actually form the vertical display boundary. If the specified container does not meet the aforementioned conditions, it is re-determined according to the ancestor node chain search method. If not specified, the ancestor container is searched along the ancestor node chain of the target table element; the calculation style of the ancestor container is obtained. When the clientHeight of the ancestor container is a finite value greater than zero and overflow-y is auto, scroll, hidden, or clip, it is determined as a candidate container; if there are multiple candidate containers, the candidate container closest to the target table element is selected. After determining the restricted parent container, the current restricted parent container reference and container size change listener reference recorded in the instance-level adaptive context are read; if no listener has been registered for this container, an element size change listener is registered for it; if the subsequently determined restricted parent container changes, the original container listener is first unloaded, then the container reference is updated and a listener is registered for the new container; if it is the same as the already recorded container, the existing listener is reused without re-registration.
[0038] The visible height is obtained through the clientHeight of the restricted parent container. ; respectively obtain the bounding rectangles of the target table element and the restricted parent container, and then... =tableRect.top-parentRect.top-parent.clientTop determines the position of the top of the target table element relative to the top of the content area of its restricted parent container. .thus, and Using browser viewport coordinates as the reference, and The coordinates of the restricted parent container's content area are used as the reference. If the target table element or the restricted parent container is hidden and the finite geometric parameters cannot be obtained, the current task is terminated and the system waits for the next update request.
[0039] When the target table element or restricted parent container is in a hidden tab, not yet mounted, or has an unmeasurable bounding rectangle size of zero, the zero value is not directly used as the basis for candidate height calculation; the height update task can be postponed to the next Vue view update completion time, the next animation frame, or after the element becomes visible again.
[0040] In the same height update task, the geometry parameter reading phase first reads the relevant geometry of the browser viewport, the target table element, and the restricted parent container, and saves the obtained values as the local measurement results for this task before proceeding to the candidate height calculation and component height writing phase. This avoids mixing geometry parameters before and after the writing process when the page layout changes due to height writing in the same task. , , and All values are in CSS pixels as used by the browser, and the bottom allowance uses the same unit.
[0041] Step S104: Calculate candidate heights, verify the validity of constraints, and determine the target height.
[0042] like Figure 2 As shown, the first candidate height based on the browser viewport. Calculate according to formula (1): (1) When a second reference display area exists, the second candidate height is based on the restricted parent container. Calculate according to formula (2): (2) in, Reserve the same bottom offset for the same parameter `bottomOffset`. (In calculation...) hour, This represents the reserved distance measured upwards from the bottom of the browser viewport; in calculation hour, This represents the reserved distance measured upwards from the bottom of the restricted parent container. Both values are the same, but the starting points for measurement differ.
[0043] When there is no second reference display area, only when When the value is a finite value greater than zero, it is determined as the height to be corrected. When a second reference display area exists, only when and When both are finite values greater than zero, the smaller value is determined as the height to be corrected. (Not in) Figure 2 (Identified separately). If any candidate height participating in the calculation is less than or equal to zero or is not a finite value, the current height update task is terminated, and another larger candidate height is not used to replace the constraint.
[0044] Let the maximum height ratio be , and 0 < ≤1; The visible height used for boundary correction is Determine the target height according to formula (3). : (3) When a second reference display area exists, Pick and The smaller value in; when there is no second reference display area, Pick This correction only reduces or maintains the height to be corrected; it will not increase the target height beyond the available space determined by the reference display area.
[0045] For example, the browser viewport visible height The top of the target table element is 900 pixels above the top of the browser viewport. 180 pixels, with a margin at the bottom. If the height is 70 pixels, then the first candidate height is... The value is 650 pixels. If the target table is within the visible height... Within a restricted parent container of 600 pixels, the position of the top of the target table element relative to the top of the container's content area. If the height is 80 pixels, then the second candidate height 450 pixels; when both are valid, the height to be corrected is... Take 450 pixels.
[0046] In another example, if For 700 pixels, 200 pixels and If it is 70 pixels, then 430 pixels; if For 800 pixels, If it is 100 pixels, then The height is 630 pixels. Although the parent container provides more vertical space, the browser viewport imposes stricter constraints, and the height needs to be adjusted. Get 430 pixels.
[0047] For example, if a second reference display area does not exist, if For 900 pixels, 750 pixels and preset maximum height ratio If it is 0.8, then 900 pixels 720 pixels, target height Use 720 pixels. This upper limit only further restricts the effective candidate height and does not change the way the reference display area and coordinate base are determined.
[0048] If the restricted parent container corresponds to A height value less than or equal to zero indicates that the container has no positive available space after deducting the top and bottom allowances of the table. In this case, the current height update is terminated, instead of ignoring the restricted parent container and using a larger value. .
[0049] For example, if For 200 pixels, 150 pixels and If it is 70 pixels, then -20 pixels indicates that the second reference display area, after deducting the top and bottom reserves of the target table element, has no positive vertical space available for the target table component; even at this point If the value is positive, the current height update task will be terminated to avoid ignoring the actual constraints of the second reference display area.
[0050] Step S105: Apply the target height and recalculate the internal layout of the target table component.
[0051] target height The current effective height recorded with the instance-level adaptive context. Comparison. When Perform the first height write when it has not been set; when If the difference is greater than updateThreshold, perform height writing and component layout recalculation; if the difference is not greater than the threshold, skip this update.
[0052] Before writing the target height, set the height application state to "Applying". If a notification of a size change in the target table element or restricted parent container caused by this height writing is received while the height is in the "Applying" state, no new height update request will be submitted; the height application state will be cleared in the next animation frame after the component layout recalculation is completed or in the next Vue view update.
[0053] The height application state is only used to suppress feedback size change notifications that can be attributed to the current target height write and subsequent layout recalculation; after the height application state is cleared, new size change notifications caused by browser window, query area, restricted parent container or other page layout changes will still submit new height update requests in step S102.
[0054] For the el-table component provided by Element UI, call `$table.layout.setHeight(H)` to write the target height to the table component's layout object. Then, when the Vue view is updated, call `$table.doLayout()` to recalculate the column widths of the header and body, fixed column areas, internal scroll areas, scrollbar states, and cell alignment. After the layout recalculation is complete, record `H` as the new, currently effective height.
[0055] Furthermore, when the custom instruction is unbound from the target table component, the listener is removed, the task is canceled, and the instance-level adaptive context is released.
[0056] When the target table component is destroyed, conditional rendering is turned off, or the route is switched, causing the custom directive to be unbound, call removeResizeListener or the corresponding observer's unbinding method to remove the size change listener for the main page and the restricted parent container, respectively; cancel the height update task that has not yet been executed; delete the directive parameters, component instance references, current effective height and height application state stored on the target table element, and remove the association between the custom directive and the target table component.
[0057] When unbinding container size change listeners, the current restricted parent container reference and corresponding listener reference recorded in the instance-level adaptive context are used as the reference. If no second reference display area is established, there is no need to perform container listener unbinding. After canceling the height update tasks that have not yet been executed, clear the component instance references and context data to prevent queued tasks from continuing to access invalid references after the component is unbound.
[0058] When multiple target table components exist on the same page, each target table component saves its own instruction parameters, component instance references, listener references, current effective height, and pending height update tasks; when any target table component is unbound, only the data and listener relationships corresponding to that target table component are cleared.
[0059] In the Vue 3 implementation, the beforeMount, mounted, and unmounted hooks can be used to handle the binding, insertion, and unbinding phases, respectively. The target table component can be a table component provided by Element Plus, and the target height application and internal layout update can be performed through the corresponding interface with height setting and layout recalculation functions.
[0060] like Figure 3 As shown, this embodiment also provides a table height adaptive system based on Vue custom directives, including a directive binding and context management module, a size change monitoring and update scheduling module, a geometric parameter acquisition and reference display area determination module, a candidate height calculation and validity verification module, a component height setting and layout update module, and a lifecycle cleanup module.
[0061] The instruction binding and context management module is used to bind custom instructions to target table components with component height setting interface and component layout recalculation interface, obtain component instance and instruction parameters, establish instance-level adaptive context, and record component interface reference, size change listening reference, task identifier, current effective height and height application status; The size change listening and update scheduling module is used to register page size change listeners and container size change listeners. When the target table component is inserted into the page or when the size change listener outputs a notification, it submits a height update request, cancels height update tasks that have not yet been executed, and recreates the height update task according to the event merging delay duration. The geometric parameter acquisition and reference display area determination module is used to determine two reference display areas in the same height update task, and acquire... , And when a second reference display area exists, obtain , The obtained geometric parameters are then saved as local measurement results. The candidate height calculation and validity verification module is used to calculate the candidate height according to the following criteria: and Calculate candidate heights. When all candidate heights involved in the constraints are finite values that are greater than zero, determine the height to be corrected. Then, determine the target height based on the ratio of the height to be corrected to the maximum height. Terminate the current height update task if any candidate height involved in the constraints is invalid. The component height setting and layout update module is used to set the height application state when the height difference update condition is met. It applies the target height through the component height setting interface, calls the component layout recalculation interface after the Vue view is updated, and writes back the currently effective height. The lifecycle cleanup module is used to read listener references and task identifiers in the instance-level adaptive context when unbinding custom directives, remove page size change listeners and container size change listeners, cancel height update tasks that have not yet been executed, clear component instance references and state data, and release the instance-level adaptive context.
[0062] The above description, in conjunction with specific embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, any equivalent substitutions, simple modifications, or combinations made without departing from the concept of the present invention should be considered within the scope of protection of the present invention.
Claims
1. A method for adaptive table height based on Vue custom directives, characterized in that, Includes the following steps: S101. Bind the custom instruction to the target table component with the component height setting interface and the component layout recalculation interface, obtain the component instance of the target table component and the instruction parameters including the bottom reserve, establish an instance-level adaptive context associated with the target table component, and register a page size change listener. S102. When the target table component is inserted into the page or when any registered size change listener outputs a size change notification, a height update request is submitted, and multiple height update requests submitted consecutively within a preset event merging delay time are merged into a height update task to be executed. S103. When performing the height update task, determine the target table element corresponding to the target table component in the document object model, and determine the browser viewport as the first reference display area. When a restricted parent container located on the ancestor node chain of the target table element forms a vertical display boundary for the target table element, the restricted parent container is determined as the second reference display area; if no container size change listener has been registered for the restricted parent container, a container size change listener is registered for it; for each reference display area, under the coordinate reference corresponding to the reference display area, the visible height of the reference display area and the position of the top of the target table element relative to the top of the reference display area are obtained; S104. Calculate the candidate height corresponding to each reference display area based on the visible height of each reference display area, the position of the top of the target table element relative to the top of the reference display area, and the bottom allowance. When only the first reference display area exists, determine the target height based on the first candidate height if the first candidate height is a finite value greater than zero. When the second reference display area exists, determine the target height based on the smaller of the first and second candidate heights only if both are finite values greater than zero. Terminate the current height update task when any candidate height involved in the calculation is less than or equal to zero or is not a finite value. S105. Apply the target height through the component height setting interface of the target table component, and call the component layout recalculation interface to recalculate the internal layout of the target table component according to the target height, and record the target height in the instance-level adaptive context as the new currently effective height.
2. The method according to claim 1, characterized in that, The custom instructions include binding hooks, insertion hooks, and unbinding hooks. The binding hook is used to obtain the component instance and the instruction parameters, establish the instance-level adaptive context, and register the page size change listener. The insertion hook is used to submit the first height update request. After determining the second reference display area, if a container size change listener has not yet been registered for the corresponding restricted parent container, a container size change listener is registered for it. If the re-determined restricted parent container changes, the original container size change listener is deactivated, and a container size change listener is registered for the re-determined restricted parent container. The instance-level adaptive context at least records the interface reference of the component instance, the instruction parameters, the page size change listener reference, the container size change listener reference, the current restricted parent container reference, the task identifier of the height update task to be executed, the current effective height, and the height application status. The unbinding hook is used to remove the registered size change listener associated with the target table component, cancel the height update task that has not yet been executed, and release the instance-level adaptive context. Different target table components in the same page have mutually isolated instance-level adaptive contexts.
3. The method according to claim 1, characterized in that, The restricted parent container is determined in any of the following ways: the container specified by the instruction parameter that is located on the ancestor node chain of the target table element and forms a vertical display boundary for the target table element is determined; or, when the instruction parameter does not specify the restricted parent container or the specified container does not meet the aforementioned conditions, an ancestor container is searched along the ancestor node chain of the target table element, and an ancestor container with a visible height of a finite value greater than zero and which forms a clipping boundary or scroll boundary through vertical overflow control is determined as a candidate container; When multiple candidate containers exist, the candidate container closest to the target table element is determined as the restricted parent container; the visible height of the content area of the restricted parent container is used as the visible height of the second reference display area; the difference between the top coordinates of the boundary rectangle of the target table element and the top coordinates of the boundary rectangle of the restricted parent container, minus the width of the top border of the restricted parent container, is used to determine the position of the top of the target table element relative to the top of the second reference display area.
4. The method according to claim 1, characterized in that, The first candidate height corresponding to the first reference display area Determined according to the following formula: When the second reference display area exists, the second candidate height corresponding to the second reference display area. Determined according to the following formula: ;in, The visible height of the first reference display area. The position of the top of the target table element relative to the top of the first reference display area. The visible height of the second reference display area. The position of the top of the target table element relative to the top of the second reference display area. Reserved space at the same bottom in the instruction parameters; when the second reference display area does not exist, in In the case of a finite number greater than zero, Height determined to be corrected When the second reference display area exists, only and When both are finite values greater than zero, the smaller of the two values is determined as the height to be corrected. .
5. The method according to claim 4, characterized in that, The target height according to It is confirmed that, among them, The preset maximum height ratio is greater than zero and not greater than 1; when the second reference display area does not exist, The visible height of the first reference display area When the second reference display area exists, The visible height of the first reference display area and the visible height of the second reference display area The smaller value in the range.
6. The method according to claim 2, characterized in that, Each time a new height update request is received, cancel any unexecuted height update tasks and recreate the height update task according to the preset event merging delay duration; only if no new height update request is received within the preset event merging delay duration, perform geometric parameter reading and candidate height calculation; when the current effective height has not been recorded, or the absolute difference between the target height and the current effective height is greater than a preset height difference threshold, execute the application of the target height and the component layout recalculation; during the call to the component height setting interface, set a height application state in the instance-level adaptive context to characterize the target height writing process, and suppress size change notifications caused by this target height writing and component layout recalculation when the height application state indicates that it is being applied; clear the height application state after the component layout recalculation is completed.
7. The method according to claim 2, characterized in that, The target table component is the el-table component provided by Element UI; the page size change listener is bound to the page body through the element size listener tool provided by Element UI, and the container size change listener is bound to the second reference display area through the element size listener tool or the element size change observer; the component height setting interface is the setHeight method provided by the layout object of the el-table component, and the component layout recalculation interface is the doLayout method provided by the el-table component, and the doLayout method is called after the Vue view is updated.
8. A table height adaptive system based on Vue custom directives, characterized in that, It includes the following modules implemented by computer programs: The instruction binding and context management module is used to bind custom instructions to a target table component with a component height setting interface and a component layout recalculation interface, obtain the component instance of the target table component and instruction parameters including bottom reservation amount, and establish an instance-level adaptive context associated with the target table component. The size change monitoring and update scheduling module is used to register page size change monitoring, submit a height update request when the target table component is inserted into the page or when any registered size change monitoring outputs a size change notification, merge consecutively submitted height update requests into a height update task to be executed, and register container size change monitoring for the second reference display area after determining it. The geometric parameter acquisition and reference display area determination module is used to determine the browser viewport as the first reference display area and the restricted parent container that forms the vertical display boundary of the target table element as the second reference display area when performing the height update task. For each reference display area, the module obtains the visible height of the reference display area and the position of the top of the target table element relative to the top of the reference display area under the coordinate reference corresponding to the reference display area. The candidate height calculation and validity verification module is used to calculate the corresponding candidate height based on the visible height of each reference display area, the position of the top of the target table element relative to the top of the corresponding reference display area, and the bottom allowance; when only the first reference display area exists and the first candidate height is a finite value greater than zero, the target height is determined based on the first candidate height; when the second reference display area exists and both the first and second candidate heights are finite values greater than zero, the target height is determined based on the smaller of the two; if any candidate height involved in the calculation is less than or equal to zero or is not a finite value, the current height update task is terminated; The component height setting and layout update module is used to apply the target height through the component height setting interface, call the component layout recalculation interface to recalculate the internal layout of the target table component according to the target height, and write the target height back to the instance-level adaptive context; The lifecycle cleanup module is used to remove the registered size change listeners associated with the target table component, cancel the height update task that has not yet been executed, and release the instance-level adaptive context when the custom instruction is unbound from the target table component.
