跪拜 Guibai
← All articles
Vue.js · Low-code

Schema-Driven Vue 3 Forms: Extending Controls Without Touching the Engine

By 全栈小卷 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Western developers building schema-driven forms in Vue 3 get a way to integrate third-party UI libraries without maintaining a separate adapter layer. Because the extension API mirrors Vue's own reactivity and scope chains, the cost of custom controls stays low enough to make schema-based forms practical for real projects.

Summary

Schema rendering engines for Vue 3 usually make third-party UI integration painful: you wrap each control in layers of adapters just to support mild customization. vue-juan-form moves that work to the user extension layer. After aligning its data-driven and link-listening internals with Vue 3's reactivity, it lets you build a custom control like FullName by composing two Input fields inside a schema, then uses dependsOn to watch givenName and familyName and write the concatenated fullName back to the field.

For dynamic behavior such as highlighting a sensitive name, the engine offers two paths. You can wrap the rendered vnode in component.render using h(), or you can stay declarative and use computed, style, and if inside the schema config, mirroring Vue SFC syntax. Hardcoded keywords can move to page-level props and be read through SchemaApi.current().props, so the same custom control becomes configurable per field. The result is a consistent extension model that keeps the engine small and gives users the escape hatches they need.

Takeaways
— vue-juan-form exposes createInput(type, config) to register a custom control; config includes schema, dependsOn, and optional render or computed.
— The schema field can nest existing control types (like Input) and HTML elements, using grid layout via col.
— dependsOn injects SchemaApi and runs a handle function on field changes; setValue() writes a concatenated value back to the current field.
— component.render receives the vnode parsed from schema; h() can wrap it with extra containers and dynamic styling.
— For dynamic styling and conditional rendering, schema config supports computed properties, style functions, and if expressions, with module injection.
— Sensitive keywords can be defined on the page-level field via props and read in the extension using SchemaApi.current().props.
— The engine aligns with Vue 3 data-driven updates and link listening, which keeps third-party UI adaptation cost low.
— The next article will show integration with Element Plus Tabs, using the component's appearance without its API.
Conclusions

Shifting third-party UI adaptation to the user layer keeps the engine small, but it transfers the integration burden to the developer building the custom control. The state.$parent/$root access shown here is powerful yet couples that developer to the engine's scope chain, while SchemaApi provides a cleaner injectable interface.

The article presents three escalating extension mechanisms: schema composition for structure, dependsOn for data flow, and render or computed for dynamic behavior. That gives a clear path from declarative to imperative without forcing a single style, which suits a low-code tool that still needs hand-written escape hatches.

Concepts & terms
createInput
Function from vue-juan-form that registers a custom schema control type. It takes a type name and a config object with schema, dependsOn, and optional render or computed extensions.
dependsOn
Configuration option in vue-juan-form that declares dependencies on other fields and provides a handle callback. The callback runs when those fields change, often using SchemaApi.setValue to write a derived value back to the current field.
SchemaApi
Injected utility object in vue-juan-form extensions. It exposes methods like getValue, setValue, and current() for reading the node's props, plus access to the state scope chain via $parent and $root.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗