Loading...
Loading...
Vue 3 renderer for json-render. Use when building Vue UIs from JSON specs, working with @json-render/vue, defining Vue component registries, or rendering AI-generated specs in Vue.
npx skill4agent add vercel-labs/json-render vuenpm install @json-render/vue @json-render/core zodvue ^3.5.0zod ^4.0.0import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/vue/schema";
import { z } from "zod";
export const catalog = defineCatalog(schema, {
components: {
Card: {
props: z.object({ title: z.string(), description: z.string().nullable() }),
description: "A card container",
},
Button: {
props: z.object({ label: z.string(), action: z.string() }),
description: "A clickable button",
},
},
actions: {},
});import { h } from "vue";
import { defineRegistry } from "@json-render/vue";
import { catalog } from "./catalog";
export const { registry } = defineRegistry(catalog, {
components: {
Card: ({ props, children }) =>
h("div", { class: "card" }, [
h("h3", null, props.title),
props.description ? h("p", null, props.description) : null,
children,
]),
Button: ({ props, emit }) =>
h("button", { onClick: () => emit("press") }, props.label),
},
});<script setup lang="ts">
import { StateProvider, ActionProvider, Renderer } from "@json-render/vue";
import { registry } from "./registry";
const spec = { root: "card-1", elements: { /* ... */ } };
</script>
<template>
<StateProvider :initial-state="{ form: { name: '' } }">
<ActionProvider :handlers="{ submit: handleSubmit }">
<Renderer :spec="spec" :registry="registry" />
</ActionProvider>
</StateProvider>
</template>| Provider | Purpose |
|---|---|
| Share state across components (JSON Pointer paths). Accepts |
| Handle actions dispatched via the event system |
| Enable conditional rendering based on state |
| Form field validation |
| Composable | Purpose |
|---|---|
| Access state context ( |
| Get single value from state |
| Check if a visibility condition is met |
| Access action context |
| Get a single action dispatch function |
| Field validation state |
| Two-way binding for |
useStateStore().stateShallowRef<StateModel>state.valueStateStoreStateProviderimport { createStateStore, type StateStore } from "@json-render/vue";
const store = createStateStore({ count: 0 });<StateProvider :store="store">
<Renderer :spec="spec" :registry="registry" />
</StateProvider>$state$bindState$cond$template$computed{ "$bindState": "/path" }{ "$state": "/user/isAdmin" }
{ "$state": "/status", "eq": "active" }
{ "$state": "/maintenance", "not": true }
[ cond1, cond2 ] // implicit ANDsetStatepushStateremoveStatevalidateFormActionProvider{
"action": "setState",
"params": { "statePath": "/activeTab", "value": "settings" }
}emit(event)on(event)shouldPreventDefaultbounduseUIStreamuseChatUIimport type { BaseComponentProps } from "@json-render/vue";
const Card = ({ props, children }: BaseComponentProps<{ title?: string }>) =>
h("div", null, [props.title, children]);| Export | Purpose |
|---|---|
| Create a type-safe component registry from a catalog |
| Render a spec using a registry |
| Element tree schema (from |
| Context providers |
| State composables |
| Action composables |
| Validation and visibility |
| Streaming composables |
| Create in-memory |
| Catalog-agnostic component props type |