Appearance
π¦ JSON-Based Routing in WBC-Routes2 β
JSON is a universal format for defining structured data β and WBC-Routes2 makes it routeable!
By passing a JSON object to a route's item prop, you can dynamically render Vue components, markdown, layout structures, and even interactive behavior, all from data.
πΉ Basic JSON Object Rendering β
You can route to a static JSON object like this:
js
{
path: "/json/basic",
name: "JsonBasic",
component: WBC,
props: {
item: {
comp: "JsonViewer",
options: {
value: { name: "Wissem", age: 30, active: true }
}
}
}
}β
The JsonViewer global component will render your object with toggles, colorized keys, and nested display.
πΈ Render Lists from JSON β
Pass JSON as arrays or objects into a list-like display using Markdown or HTML renderers.
js
{
path: "/json/list",
name: "JsonList",
component: WBC,
props: {
item: {
comp: "MD",
options: {
html: "<~ol>",
src: "- Item 1\n- Item 2\n- Item 3"
}
}
}
}π§© Combine this with interactive buttons or file content to build dashboards on-the-fly.
πΈ JSON with Events β
Inject interactivity through event bindings in the options.on object.
js
{
path: "/json/event",
name: "JsonEvent",
component: WBC,
props: {
item: {
comp: "VBtn",
dive: true,
options: {
class: "success",
html: "Click me",
on: {
click: that => () => {
alert("Hello from JSON-driven route!");
}
}
}
}
}
}π‘ Youβre not limited to read-only data. Full event lifecycles are supported.
π Dynamic JSON Mapped to Layouts β
Here's a full Vue layout mapped from structured JSON:
js
{
path: "/json/layout",
name: "JsonLayout",
component: WBC,
props: {
item: [
"<~VContainer|pa-5 grey lighten-4>",
"<VRow|justify-center>",
{
comp: "VCol",
options: {
cols: 6,
html: {
comp: "VAlert",
options: {
type: "info",
text: true,
html: "Rendered from JSON layout"
}
}
}
}
]
}
}π You can control columns, rows, colors, spacing, and more β all from JSON.
π§ͺ Reactive JSON with dive β
To make the JSON reactive (data-bound), use:
js
{
dive: true,
comp: "div",
options: {
html: "Your score is: ``{this.score}",
on: {
mounted: that => {
that.score = 42;
}
}
}
}π Now any property you assign inside that becomes available to interpolate in your text and children components.
β Summary β
| Feature | Supported |
|---|---|
| JSON to Vue Layouts | β |
| Dynamic Event Binding | β |
| Reactive Properties | β |
| File + JSON Mix | β |
| Multi-language JSON | β |