Dynamic form rendering system and method based on Vue
Through the Vue-based dynamic form rendering system, Vue's calculated properties and responsive data binding technology are used to solve the problems of dynamic form complexity, low performance and insufficient flexibility in the existing technology, and achieve efficient and flexible form development. and optimize user experience.
Patent Information
- Application Number
- CN202410788227.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-19
AI Technical Summary
Existing JavaScript-based dynamic form solutions are complex, have low performance, and lack flexibility, resulting in high development difficulty, performance issues, and degraded user experience.
Using a dynamic form rendering system based on Vue, through project initialization, defining form data, writing dynamic form components, submission and verification modules and form usage modules, Vue's calculated properties and responsive data binding technology are used to realize the rendering and rendering of dynamic forms. Verification, using asynchronous components and throttling and anti-shake strategies to optimize performance.
It improves development efficiency and flexibility, optimizes performance, reduces manual coding errors, and improves user interaction experience and code maintainability.
Smart Images

Figure CN118363578B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software program development, and in particular to a Vue-based dynamic form rendering system and method. Background Art
[0002] In modern web application development, forms are one of the main ways for users to interact with applications. Traditional forms are usually composed of static HTML elements, whose structure and style are determined during development. However, as the complexity of web applications increases, the limitations of static forms become more significant.
[0003] At present, there are already some technical solutions for implementing dynamic form rendering, including but not limited to JavaScript-based dynamic form libraries, React-based dynamic form components, etc. These solutions usually rely on manually written JavaScript code to dynamically generate form elements and communicate with the backend to obtain form structure and data. Although these solutions have achieved dynamic form rendering to a certain extent, they have some defects: 1. Complexity: Existing JavaScript-based dynamic form solutions usually require a lot of manual coding to manage the state of the form, verify input, handle events, etc. This increases the workload of developers and increases the possibility of errors; 2. Performance: In large-scale form applications, due to frequent and complex DOM operations, JavaScript-based dynamic forms may cause performance problems, such as slow page loading and degraded user experience; 3. Flexibility: Existing solutions have certain limitations in handling dynamic form structure changes. For example, when the form structure needs to change dynamically based on user input or specific conditions, existing solutions may not provide sufficient flexibility and scalability.
[0004] In summary, a Vue-based dynamic form rendering system and method is needed to solve the deficiencies in the prior art. Summary of the invention
[0005] In view of the deficiencies in the prior art, the present invention provides a Vue-based dynamic form rendering system and method, aiming to solve the above problems.
[0006] To achieve the above object, the present invention provides the following technical solution: a dynamic form rendering system based on Vue, including a project initialization module, a form data definition module, a dynamic form writing module, a submission and verification module and a form use module,
[0007] The project initialization module is used to create a Vue project, build the project structure, and install the validation form library and related dependencies;
[0008] Define the form data module, which is used to configure the form structure, field type, validation rules and the relationship between fields through a visual interface or programmatically;
[0009] Write a dynamic form module to create a Vue component, use the v-for directive to traverse the form data structure, use Vue's calculated property feature to create a calculated property for each form item that needs to be validated, and automatically run according to the current form data and validation rules to check whether the data meets the rules and bind Vue properties;
[0010] The submission and verification module is used to implement dynamic form verification using Vue calculated properties, use asynchronous components to process large amounts of data or infrequently used form parts, implement on-demand loading through component splitting, and use throttling and anti-shake strategies to optimize high-frequency event processing;
[0011] The form usage module is used to introduce instantiation components and pass in the required form data structure to complete dynamic form rendering when dynamic forms are needed.
[0012] A dynamic form rendering method based on Vue, comprising the following steps:
[0013] Step S1: Initialize the project, create a Vue project, and build the project structure;
[0014] Step S2: Prepare form data, initialize the form data model, form data structure and validation rule object in the data function of the Vue instance, configure the form, and describe the fields and properties contained in the form;
[0015] Step S3: Write a dynamic form component, create a Vue component, use the v-for instruction to traverse the form data structure, generate corresponding form controls according to the type of each field, and bind Vue attributes;
[0016] Using the calculated property feature of Vue, create a calculated property for each form item that needs to be validated, and automatically run it according to the current form data and validation rules to check whether the data meets the rules;
[0017] Step S4: Process form submission and verification. In the dynamic form component, listen to the submit event of the form, trigger form verification and process the submission logic;
[0018] Step S5: Use the dynamic form component. When the dynamic form needs to be used, introduce the instantiation component, pass in the required form data structure, and complete the dynamic form rendering.
[0019] Optionally, the dynamic form component written in step S3 is to dynamically generate a corresponding Vue component based on the form configuration information, and adopt the responsive data binding technology of the Vue framework, traverse the configuration array through the v-for instruction, and dynamically render the form interface according to the configuration information, so that the form structure is automatically updated as the configuration changes.
[0020] Optionally, in step S4, Vue calculated properties are used to implement dynamic form verification, asynchronous components are used to process large amounts of data or infrequently used form parts, on-demand loading is achieved through component splitting, and throttling and anti-shake strategies are used to optimize high-frequency event processing.
[0021] Optionally, the asynchronous component processing in step S4 is:
[0022] Split large forms into multiple small, independently loadable components or page parts. For frequently triggered event handlers, apply throttling or anti-shake technology to reduce the execution frequency of event handler functions.
[0023] A function is executed only once within a specific time interval, that is, if an event is triggered multiple times within a period of time, the function will only be executed once.
[0024] If it is triggered again within the specified time, the previous timer is cleared and restarted. When the delay time after the last trigger arrives, the function is executed.
[0025] Optionally, the submission and verification of the form in step S4 is performed in the following manner:
[0026] The process of obtaining and submitting form data and verifying data validity includes real-time monitoring of user input, performing validation operations according to pre-set validation rules, and submitting the validated data to the backend server when the user submits the form.
[0027] Optionally, the dynamic form rendering in step S5 is to load and present the Vue component through a form renderer, and dynamically generate different form structures according to user input.
[0028] Optionally, the form configuration information in step S2 includes field name, field type, field title, whether it is required, default value, maximum and minimum length limits of the field, regular expression validation rules, and linkage display logic with other fields.
[0029] Optionally, the Vue dynamic form rendering adopts the Vue framework features to create complex dynamic forms in a simple way.
[0030] Optionally, the third-party library for form validation is vuelidate or vee-validate.
[0031] Beneficial effects of the present invention:
[0032] 1. In the present invention, the use of Vue-based dynamic form rendering components can greatly improve development efficiency; developers do not need to manually write a large amount of JavaScript code to manage the state and validation rules of the form, but can quickly create a complex form structure through a simple configuration method. The Vue framework provides a powerful data binding and componentization mechanism, making the development of forms simpler and more efficient, providing higher flexibility and scalability. Developers can easily adjust the form structure according to business needs, add or delete fields, without modifying a large amount of code. The responsive data binding and componentization mechanism of the Vue framework allows the structure of the form to change dynamically according to data changes;
[0033] 2. In the present invention, the dynamic form rendering component based on Vue can optimize performance. The Vue framework realizes efficient page updates through virtual DOM technology, only updating the parts that actually change instead of re-rendering the entire page, which can reduce unnecessary DOM operations and improve page rendering efficiency, thereby improving the user's interactive experience when using the form;
[0034] 3. In the present invention, the dynamic form rendering component reduces the need to manually write a large amount of JavaScript code, and reduces the possibility of errors in the development process. Since developers only need to focus on the configuration and business logic of the form without having to worry about the underlying DOM operations and data management, the chance of errors is reduced and the maintainability and stability of the code are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A structural schematic diagram of the system of the present invention.
[0036] Figure 2 A schematic diagram of a process of the method of the present invention. DETAILED DESCRIPTION
[0037] In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0038] like Figure 1 As shown in the figure, a dynamic form rendering system based on Vue includes a project initialization module, a form data definition module, a dynamic form writing module, a submission and verification module, and a form use module.
[0039] The project initialization module is used to create a Vue project, build the project structure, and install the validation form library and related dependencies;
[0040] Define the form data module, which is used to configure the form structure, field type, validation rules and the relationship between fields through a visual interface or programmatically;
[0041] Write a dynamic form module to create a Vue component, use the v-for directive to traverse the form data structure, use Vue's calculated property feature to create a calculated property for each form item that needs to be validated, and automatically run according to the current form data and validation rules to check whether the data meets the rules and bind Vue properties;
[0042] The submission and verification module is used to implement dynamic form verification using Vue calculated properties, use asynchronous components to process large amounts of data or infrequently used form parts, implement on-demand loading through component splitting, and use throttling and anti-shake strategies to optimize high-frequency event processing;
[0043] The form usage module is used to introduce instantiation components and pass in the required form data structure to complete dynamic form rendering when dynamic forms are needed.
[0044] like Figure 2 As shown, a dynamic form rendering method based on Vue includes the following steps:
[0045] Step S1: Initialize the project, create a Vue project, and build the project structure;
[0046] Step S2: Prepare form data, initialize the form data model, form data structure and validation rule object in the data function of the Vue instance, configure the form, and describe the fields and properties contained in the form;
[0047] Form configuration information includes field name, field type, field title, whether it is required, default value, maximum and minimum field length limits, regular expression validation rules, and linkage display logic with other fields.
[0048] Step S3: Write a dynamic form component, create a Vue component, use the v-for instruction to traverse the form data structure, generate corresponding form controls according to the type of each field, and bind Vue attributes;
[0049] Writing dynamic form components is to dynamically generate corresponding Vue components based on form configuration information, and adopt the responsive data binding technology of Vue framework. Through the v-for instruction, the configuration array is traversed, and the form interface is dynamically rendered according to the configuration information, so that the form structure is automatically updated as the configuration changes;
[0050] Using the calculated property feature of Vue, create a calculated property for each form item that needs to be validated, and automatically run it according to the current form data and validation rules to check whether the data meets the rules;
[0051] Step S4: Process form submission and verification. In the dynamic form component, listen to the submit event of the form, trigger form verification and process the submission logic. Use a third-party library for form verification, or customize the verification method.
[0052] Define a submission processing function in the Vue instance. This function traverses the form items, calls the calculated properties or direct validation methods, summarizes the validation results, and prevents form submission and prompts an error if there are items that fail the validation.
[0053] Use Vue calculated properties to implement dynamic form validation, use asynchronous components to process large amounts of data or infrequently used form parts, implement on-demand loading through component splitting, and use throttling and anti-shake strategies to optimize high-frequency event processing;
[0054] Asynchronous component processing is:
[0055] Split large forms into multiple small, independently loadable components or page parts. For frequently triggered event handlers, apply throttling or anti-shake technology to reduce the execution frequency of event handler functions.
[0056] A function is executed only once within a specific time interval, that is, if an event is triggered multiple times within a period of time, the function will only be executed once.
[0057] If it is triggered again within the specified time, the previous timer will be cleared and restarted. When the delay time after the last trigger is reached, the function will be executed;
[0058] For example: when a page scrolls frequently, a scroll border is generated on the page. At this time, the scroll border scrolls frequently, the visible area in the page does not scroll, and only the elements in the visible area are rendered, which greatly reduces the execution frequency of the event processing function and prevents excessive rendering.
[0059] The process of obtaining and submitting form data and verifying data validity, including real-time monitoring of user input, performing verification operations according to pre-set verification rules, and submitting verified data to the backend server when the user submits the form;
[0060] Step S5: Use the dynamic form component to introduce the instantiation component in the dynamic form where the dynamic form is needed, pass in the required form data structure, and complete the dynamic form rendering;
[0061] Real-time input monitoring and feedback: Use Vue's watch feature to configure listeners for key form items and feedback the verification status on the interface;
[0062] Dynamic form rendering is to load and present the Vue component through the form renderer, and dynamically generate different form structures according to user input;
[0063] Vue's dynamic form rendering uses the Vue framework features to create complex dynamic forms in a simple way. The third-party library for form validation uses vuelidate or vee-validate.
[0064] This technical solution also provides a high-frequency event processing strategy optimization step.
[0065] Optimization step 1, high-frequency event detection, after detecting high-frequency events, according to the classification of high-frequency events, the preset loading strategy is executed. The high-frequency events include multiple repeated inputs of the same type of instructions, and the repeated inputs here include continuous single repeated inputs of the same type or the same signal within a certain period of time and different inputs in the continuous same type of input signals, continuous single repeated inputs of the same type or the same signal, such as continuous page turning operations; different inputs in the same type of input signals, the input here can include various forward operations and subsequent opposite or undo operations, such as page turning up and page turning down, character left shift and character right shift, etc. The detection method of high-frequency signals includes distinguishing the type, object and action of the input signal within a set time. Correspondingly, the classification of high-frequency events is also comprehensively classified according to the type, object and action of the input signal. A typical high-frequency event is a high-frequency operation of the mouse wheel. For example, the page slides up and down caused by the generally defined mouse wheel operation. When a single scroll input is performed, the page can be completely rendered and slid up or down synchronously. At this time, the computing resources consumed are relatively limited. The difference between the form rendering time and the page sliding time is not much, and it is meaningful to render the page form. However, if the page slides up and down caused by the mouse wheel operation is repeated many times in a certain period of time, a large amount of computing resources are required to render the form. The rendering results are displayed on the computer page. It is of little significance. Moreover, with the existence of a large number of rendering resources, if we only emphasize the timely rendering, it will cause overall response delays and display slowdowns, which will lead to a decline in customer experience.
[0066] Optimization step 2: execute the preset loading strategy until the high-frequency event ends; the loading strategy uses low-cost rendering to feedback the response of the current action. The preset loading strategy includes at least the schematic loading strategy, the key local loading strategy, and the outer frame loading strategy. The differences between the three are represented by the typical high-frequency operation of the mouse wheel:
[0067] A2.1 Schematic loading strategy requires the current form to be a common default form, which generally corresponds to a pre-stored schematic. When the schematic loading strategy is executed, the form is not rendered as a whole, but the pre-stored schematic is selected to replace the original form to perform the corresponding action. Specifically, when the user performs a large number of repeated mouse scrolling and page scrolling operations, the form including its content is directly animated into a schematic diagram, which is used to scroll and scroll the screen until the large number of repeated mouse scrolling and page scrolling operations stop.
[0068] A2.2 Focused local loading strategy requires that the focus of the current form is extremely prominent, that is, most of the content expressed is for a certain unit or a certain area, and a large amount of key information is in this area, such as a certain curve chart, etc. When the focused local loading strategy is executed, the form is not rendered as a whole, but a low-resolution image of the key area is selected to replace the original form to perform the corresponding action. Specifically, when the user performs a large number of repeated mouse scrolling and page scrolling operations, the key area in the form is directly converted into a lower-resolution rendering image, and this lower-resolution rendering image is scrolled and scrolled on the screen until the large number of repeated mouse scrolling and page scrolling operations stop.
[0069] A2.3 Outer frame loading strategy. If the current form is neither a common form with default settings nor a form where most of the content serves a certain unit or area, and a large amount of key information is in this area, you can choose to use the outer frame loading strategy. This strategy can be used as a fallback strategy. Specifically, when the user performs a large number of repeated mouse scrolling and page scrolling operations, the form frame and the content in the form that should be activated do not act, and the outer frame of the form is copied and shrunk proportionally to form an independent frame. The frame corresponds proportionally to the outer frame of the area where the form should be activated. The color contrast of the independent frame is manually preset, and this independent frame replaces the area that should be activated to perform scrolling and page scrolling feedback on the screen until a large number of repeated mouse scrolling and page scrolling operations stop.
[0070] Optimization step three, exit the preset loading strategy and perform the corresponding form rendering. Since the high-frequency event is over, the operation of the high-frequency event is recorded, and the overall action result is determined, therefore, the corresponding content refresh and rendering can be performed according to the accumulated operation results of the high-frequency event during this period.
[0071] A3.1 The schematic diagram loading strategy ends, and the schematic diagram exit animation is loaded. At the same time, the corresponding content in the current page is refreshed and rendered. When the content is loaded, a preset method that matches the schematic diagram exit animation can be selected for loading. For example, the animation effect of loading the schematic diagram exit is a fade-out effect, and the animation effect when the content is loaded is a fade-in effect.
[0072] A3.2 When the key local loading strategy ends, the low-resolution image of the key area is first enhanced to improve the resolution of the current key area, and then the loading is carried out in a diffusion manner around the key area. During the loading and rendering process, both the loading efficiency and the consistency between the key area and other areas are maintained.
[0073] A3.3 The outer frame loading strategy is completed, and then the independent frame is enlarged to the size of the outer frame of the original form. At this time, the corresponding content in the current page can be refreshed and rendered.
[0074] In the Vue-based dynamic form rendering scenario, the above high-frequency event handling strategy optimization steps are all implemented through Vue's responsive characteristics, custom instructions, componentized design, and Vuex state management mechanisms.
[0075] First, high-frequency event detection and classification, create custom instructions: In Vue, create a custom instruction (for example, v-scroll-throttle) to listen to high-frequency events such as scrolling, and implement event frequency detection in the logic of the instruction. Identify high-frequency events by maintaining a timer or using debounce and throttle functions. Use Vuex to store the status and classification information of high-frequency events. When a high-frequency event is detected, update the status in Vuex, which will automatically notify all components that rely on these states.
[0076] Secondly, the Vue implementation of the preset loading strategy, for each loading strategy (schematic diagram, key parts, outer frame), design independent Vue components. These components are responsible for displaying corresponding visual feedback based on the current loading strategy status obtained from Vuex.
[0077] Schematic loading component: displays pre-stored schematics and listens to high-frequency event end signals to trigger the loading and fade-in animation of the actual content.
[0078] Focus on local loading components: Only render low-resolution versions of key areas. After high-frequency events are over, gradually increase the resolution and expand to the full content.
[0079] Outer frame loading component: Create a simplified component that represents the outer frame of the form, resize it as needed, and restore the rendering of the original form when the event ends.
[0080] Dynamic switching and rendering
[0081] Dynamic components and conditional rendering: Use <component :is="currentLoadingStrategyComponent">Dynamically switch loading strategy components. currentLoadingStrategyComponent is bound to the variable representing the current loading strategy state in Vuex, so as to automatically select and render the correct strategy component according to the state.
[0082] Exit strategy and content refresh: When Vue detects the sign that a high-frequency event in Vuex has ended, it triggers the exit animation of the corresponding component, and loads and renders the final form content through Vue's lifecycle hooks (such as mounted() or updated()).
[0083] In the above embodiment, a custom Vue directive, such as v-scroll-throttle, is attached to the DOM element that is expected to monitor high-frequency interactions such as scrolling. Behind this directive is a method handlerMethod, which is executed every time a scroll event is triggered. Based on this, logic is implemented to monitor the frequency of events. If it is found that the user is performing the same or similar operations in rapid succession (such as fast page turning or scrolling), the Vuex state management library will be notified to update a state variable to mark that it is currently in a high-frequency event period.
[0084] Then, Vue's componentization feature is used to dynamically display different loading strategies. According to the current loading strategy status recorded in Vuex (such as "schematic diagram loading", "focused local loading" or "outer frame loading"), the Vue application will choose to render a corresponding component, that is, once a high-frequency event is detected, the interface will immediately switch to an optimized loading view, which may be simplified content, schematic diagrams, or a frame without displaying content, thereby reducing the computational burden.
[0085] For each loading strategy, a dedicated Vue component is designed:
[0086] Schematic loading component: When needed, it displays a predefined simple graphic that roughly matches the appearance of the form, and moves smoothly with the user's scrolling action until the high-frequency scrolling ends. At this time, the component triggers a transition animation to load the completed real form content.
[0087] Focused partial loading component: If there is a particularly important part in the form, this component only renders a low-quality version of that key area, and gradually increases the quality to full resolution as you scroll, while the surrounding non-core areas slowly fill in to maintain visual coherence.
[0088] Outer frame loading component: As a fallback solution, if the first two are not applicable, this component only displays the outer frame outline of the form and may adjust the size according to the scroll position until the operation is smooth, and then load the complete form details.
[0089] Finally, when Vue senses the end of the high-frequency event signal from Vuex, it will automatically trigger the logic of exiting the current loading strategy, perform the necessary animation effects, and load the complete and latest form data for rendering. The whole process is seamless, which can optimize performance and maximize the user experience as much as possible.
[0090] This technical solution uses Vue's computed property caching feature to avoid unnecessary calculations, and reduces the initial loading time through asynchronous components and route lazy loading, ensuring efficient data acquisition logic and avoiding complex calculations or frequent API calls in the rendering loop.
[0091] A function is executed only once within a specific time interval. It is suitable for scenarios that are triggered continuously and care about the most recent operation of the event, such as updating the position indicator when the page is scrolling, real-time feedback when dragging, etc. For example, when you browse a long web page and pull the scroll bar down, the prompt information on the page does not need to be updated with every scroll you make. It is enough to update it once after the scroll stops for a while.
[0092] Execute the function after the event stops triggering for a period of time. It is suitable for those who do not care about the intermediate process of event triggering, but only care about the final operation, such as input suggestions in the search box, real-time verification of the form, etc. For example: if you quickly enter text in the search box, the system will not immediately search for matching results for each key press, but wait until you pause and make sure that you will not enter any new letters before executing the search operation.
[0093] The present invention adopts Vue's dynamic form rendering component solution and uses the characteristics of the Vue framework, such as data binding and componentization, so that developers can create complex dynamic forms through simple configuration methods without manually writing a large amount of JavaScript code, which greatly improves development efficiency.
[0094] Vue's dynamic form rendering component solution provides higher flexibility and customizability. Developers can customize the form structure and style according to specific business needs, and flexibly configure form fields, validation rules, etc., so that developers can better adapt to different business scenarios.
[0095] The Vue framework achieves efficient page updates through virtual DOM technology and responsive data binding. It only updates the parts that have actually changed instead of re-rendering the entire page. This can reduce unnecessary DOM operations and improve page rendering efficiency, thereby improving the user's interactive experience when using forms.
[0096] Vue's dynamic form rendering component solution is well integrated with the Vue framework and its ecosystem. Developers can directly use Vue's various functions and plug-ins to extend and customize forms. At the same time, Vue has rich community and documentation resources, so developers can easily get support and solve problems.
[0097] Vue's dynamic form rendering component solution reduces the need to manually write large amounts of JavaScript code and reduces the possibility of errors during the development process. Developers only need to focus on the form configuration and business logic without having to worry about underlying DOM operations and data management, thereby improving the maintainability and stability of the code.
[0098] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modification, equivalent substitution or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.< / component>
Claims
1. A dynamic form rendering system based on Vue, characterized in that: Including project initialization module, form data definition module, dynamic form writing module, submission and verification module and form use module, The project initialization module is used to create a Vue project, build the project structure, and install the validation form library and related dependencies; Define the form data module, which is used to configure the form structure, field type, validation rules and the relationship between fields through a visual interface or programmatically; Write a dynamic form module to create a Vue component, use the v-for directive to traverse the form data structure, use Vue's calculated property feature to create a calculated property for each form item that needs to be validated, and automatically run according to the current form data and validation rules to check whether the data meets the rules and bind Vue properties; The submission and verification module is used to implement dynamic form verification using Vue calculated properties, use asynchronous components to process large amounts of data or infrequently used form parts, implement on-demand loading through component splitting, and use throttling and anti-shake strategies to optimize high-frequency event processing; According to the classification of high-frequency events, the preset loading strategy is executed until the high-frequency event ends; the loading strategy adopts low-consumption rendering performance to feedback the response of executing the current action, and the preset loading strategy includes at least a schematic loading strategy, a key local loading strategy, and an outer frame loading strategy: The schematic loading strategy requires that the current form is a form with common default settings. Such forms generally correspond to pre-stored schematics. When the schematic loading strategy is executed, the form is not rendered as a whole, but the pre-stored schematic is called to replace the original form to perform the corresponding action; The key local loading strategy requires that the focus of the current form is extremely prominent, that is, most of the content expressed is for a certain unit or a certain area, and a large amount of key information is in this area. When the key local loading strategy is executed, the form is not rendered as a whole, but a low-resolution image of the key area is selected to replace the original form to perform the corresponding action; Outer frame loading strategy: if the current form is neither a common default form nor one where most of the content is for a certain unit or area, and a large amount of key information is in this area, choose to use the outer frame loading strategy. Specifically, when the user performs a large number of repeated mouse scrolling and page scrolling operations, the form frame and the content in the form that should be moved will not be moved. The outer frame of the form will be copied and shrunk proportionally to form an independent frame. The form usage module is used to introduce instantiation components and pass in the required form data structure to complete dynamic form rendering when dynamic forms are needed.
2. A dynamic form rendering method based on Vue, characterized in that: The following steps are involved: Step S1: Initialize the project, create a Vue project, and build the project structure; Step S2: Prepare form data, initialize the form data model, form data structure and validation rule object in the data function of the Vue instance, configure the form, and describe the fields and properties contained in the form; Step S3: Write a dynamic form component, create a Vue component, use the v-for instruction to traverse the form data structure, generate corresponding form controls according to the type of each field, and bind Vue attributes; Using the calculated property feature of Vue, create a calculated property for each form item that needs to be validated, and automatically run it according to the current form data and validation rules to check whether the data meets the rules; Step S4: Process form submission and verification. In the dynamic form component, listen to the form submit event, trigger form verification and process the submission logic. Use Vue calculated properties to implement dynamic form validation, use asynchronous components to process large amounts of data or infrequently used form parts, implement on-demand loading through component splitting, and use throttling and anti-shake strategies to optimize high-frequency event processing. Asynchronous component processing is: Split large forms into multiple small, independently loadable components or page parts. For frequently triggered event handlers, apply throttling or anti-shake technology to reduce the execution frequency of event handler functions. A function is executed only once within a specific time interval, that is, if an event is triggered multiple times within a period of time, the function will only be executed once. If it is triggered again within the specified time, the previous timer will be cleared and restarted. When the delay time after the last trigger is reached, the function will be executed. The processing of high-frequency events is: According to the classification of high-frequency events, the preset loading strategy is executed until the high-frequency event ends; the loading strategy adopts low-consumption rendering performance to feedback the response of executing the current action, and the preset loading strategy includes at least a schematic loading strategy, a key local loading strategy, and an outer frame loading strategy: The schematic loading strategy requires that the current form is a form with common default settings. Such forms generally correspond to pre-stored schematics. When the schematic loading strategy is executed, the form is not rendered as a whole, but the pre-stored schematic is called to replace the original form to perform the corresponding action; The key local loading strategy requires that the focus of the current form is extremely prominent, that is, most of the content expressed is for a certain unit or a certain area, and a large amount of key information is in this area. When the key local loading strategy is executed, the form is not rendered as a whole, but a low-resolution image of the key area is selected to replace the original form to perform the corresponding action; Outer frame loading strategy: if the current form is neither a common default form nor one where most of the content is for a certain unit or area, and a large amount of key information is in this area, choose to use the outer frame loading strategy. Specifically, when the user performs a large number of repeated mouse scrolling and page scrolling operations, the form frame and the content in the form that should be moved will not be moved. The outer frame of the form will be copied and shrunk proportionally to form an independent frame. Step S5: Use the dynamic form component. When the dynamic form needs to be used, introduce the instantiation component, pass in the required form data structure, and complete the dynamic form rendering.
3. According to the Vue-based dynamic form rendering method of claim 2, it is characterized in that: Writing the dynamic form component in step S3 is to dynamically generate the corresponding Vue component based on the form configuration information, and adopt the responsive data binding technology of the Vue framework. The configuration array is traversed through the v-for instruction, and the form interface is dynamically rendered according to the configuration information, so that the form structure is automatically updated as the configuration changes.
4. According to the Vue-based dynamic form rendering method of claim 2, it is characterized in that: The submission and verification of the form in step S4 is performed in the following manner: The process of obtaining and submitting form data and verifying data validity includes real-time monitoring of user input, performing validation operations according to pre-set validation rules, and submitting the validated data to the backend server when the user submits the form.
5. According to the Vue-based dynamic form rendering method of claim 2, it is characterized in that: The dynamic form rendering in step S5 is to load and present the Vue component through the form renderer, and dynamically generate different form structures according to user input.
6. According to the Vue-based dynamic form rendering method of claim 2, it is characterized in that: The form configuration information in step S2 includes field name, field type, field title, whether it is required, default value, maximum and minimum length limits of the field, regular expression validation rules, and linkage display logic with other fields.
7. The Vue-based dynamic form rendering method according to claim 3 is characterized in that: The dynamic form rendering of Vue adopts the features of the Vue framework to create complex dynamic forms in a simple way.
8. According to the Vue-based dynamic form rendering method of claim 3, it is characterized in that: The third-party library for form validation is vuelidate or vee-validate.
