vue-json-schema-form
基于Vue/Vue3,Json Schema 和 ElementUi/antd/iview3/naiveUi 等生成 HTML Form 表单,用于活动编辑器、h5编辑器、cms等数据配置;支持可视化生成表单Schema 。 Generate a form using Vue/Vue3, Json Schema and ElementUi/antdv/iview3/naiveUi
Top Related Projects
A React component for building Web forms from JSON Schema.
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
A React library for building forms from any schema.
Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
Quick Overview
The lljj-x/vue-json-schema-form
project is a Vue.js library that provides a powerful and flexible way to generate forms based on JSON Schema definitions. It allows developers to quickly create complex forms with minimal code, while still providing a high degree of customization and control.
Pros
- Declarative Approach: The library uses a declarative approach to form generation, allowing developers to define the form structure using a JSON Schema, rather than manually building the form UI.
- Customization: The library provides a wide range of customization options, allowing developers to easily modify the appearance and behavior of the generated forms.
- Validation: The library automatically handles form validation based on the JSON Schema definition, reducing the amount of boilerplate code required.
- Extensibility: The library is designed to be highly extensible, with support for custom components and validators, making it easy to integrate with existing projects.
Cons
- Learning Curve: The library has a relatively steep learning curve, as developers need to understand both Vue.js and JSON Schema in order to use it effectively.
- Performance: The library may have some performance overhead, especially for large or complex forms, due to the dynamic nature of the form generation process.
- Limited Ecosystem: The library is relatively new and has a smaller ecosystem compared to some other form libraries, which may limit the availability of third-party components and plugins.
- Dependency on Vue.js: The library is tightly coupled with the Vue.js framework, which may be a limitation for developers who are not using Vue.js in their projects.
Code Examples
Defining a Form using JSON Schema
const schema = {
type: 'object',
properties: {
name: {
type: 'string',
title: 'Name',
description: 'Enter your name'
},
email: {
type: 'string',
title: 'Email',
description: 'Enter your email address',
format: 'email'
},
age: {
type: 'integer',
title: 'Age',
description: 'Enter your age',
minimum: 18,
maximum: 100
}
},
required: ['name', 'email', 'age']
};
Rendering the Form in a Vue.js Component
<template>
<vue-json-schema-form
:schema="schema"
v-model="formData"
@submit="onSubmit"
/>
</template>
<script>
import VueJsonSchemaForm from 'vue-json-schema-form';
export default {
components: {
VueJsonSchemaForm
},
data() {
return {
schema,
formData: {}
};
},
methods: {
onSubmit(data) {
console.log('Form submitted:', data);
}
}
};
</script>
Customizing the Form Layout
<template>
<vue-json-schema-form
:schema="schema"
v-model="formData"
@submit="onSubmit"
:ui-schema="uiSchema"
/>
</template>
<script>
import VueJsonSchemaForm from 'vue-json-schema-form';
export default {
components: {
VueJsonSchemaForm
},
data() {
return {
schema,
uiSchema: {
'ui:layout': [
['name', 'email'],
['age']
]
},
formData: {}
};
},
methods: {
onSubmit(data) {
console.log('Form submitted:', data);
}
}
};
</script>
Getting Started
To get started with the lljj-x/vue-json-schema-form
library, follow these steps:
- Install the library using npm or yarn:
npm install vue-json-schema-form
- Import the
VueJsonSchemaForm
component in your Vue.js application:
import V
Competitor Comparisons
A React component for building Web forms from JSON Schema.
Pros of react-jsonschema-form
- More mature and widely adopted project with a larger community
- Extensive documentation and examples
- Built-in support for custom widgets and fields
Cons of react-jsonschema-form
- Limited to React ecosystem, while vue-json-schema-form supports Vue
- Steeper learning curve for complex customizations
- Larger bundle size compared to vue-json-schema-form
Code Comparison
react-jsonschema-form:
import Form from "@rjsf/core";
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" }
}
};
<Form schema={schema} onSubmit={onSubmit} />
vue-json-schema-form:
<template>
<VueForm
v-model="formData"
:schema="schema"
@submit="onSubmit"
/>
</template>
<script>
import VueForm from '@lljj/vue-json-schema-form';
export default {
components: { VueForm },
data() {
return {
schema: {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
}
},
formData: {}
};
},
methods: {
onSubmit(formData) {
// Handle form submission
}
}
};
</script>
Both libraries provide similar functionality for rendering JSON Schema-based forms, but react-jsonschema-form offers more advanced features and customization options at the cost of increased complexity.
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
Pros of jsonform
- More mature project with longer development history
- Supports multiple JavaScript frameworks, not limited to Vue.js
- Extensive documentation and examples available
Cons of jsonform
- Less active development and maintenance
- May lack some modern features and optimizations
- Potentially steeper learning curve for complex forms
Code Comparison
vue-json-schema-form:
<template>
<VueForm
v-model="formData"
:schema="schema"
:ui-schema="uiSchema"
/>
</template>
jsonform:
$('form').jsonForm({
schema: {
name: { type: 'string', title: 'Name', required: true },
age: { type: 'number', title: 'Age', minimum: 0 }
}
});
Key Differences
- Framework: vue-json-schema-form is specifically designed for Vue.js, while jsonform is more framework-agnostic.
- Syntax: vue-json-schema-form uses Vue component syntax, whereas jsonform uses jQuery-style initialization.
- Customization: vue-json-schema-form offers more fine-grained control over form rendering through ui-schema.
- Performance: vue-json-schema-form likely has better performance due to Vue.js reactivity system.
- Learning Curve: vue-json-schema-form may be easier to learn for Vue.js developers, while jsonform might be more accessible for developers familiar with jQuery.
A React library for building forms from any schema.
Pros of uniforms
- Supports multiple UI frameworks (React, Vue, Angular)
- More extensive documentation and examples
- Active community and regular updates
Cons of uniforms
- Steeper learning curve due to its flexibility
- May require more setup for complex forms
Code Comparison
uniforms:
import { AutoForm } from 'uniforms-semantic';
import { bridge as schema } from './schema';
const MyForm = () => (
<AutoForm schema={schema} onSubmit={console.log} />
);
vue-json-schema-form:
<template>
<vue-form
v-model="formData"
:schema="schema"
@submit="handleSubmit"
/>
</template>
<script>
import VueForm from '@lljj/vue-json-schema-form';
</script>
Both libraries aim to simplify form creation based on JSON schemas, but they differ in their approach and ecosystem support. uniforms offers more flexibility and framework options, while vue-json-schema-form provides a more straightforward implementation specifically for Vue.js applications. The code comparison shows that uniforms uses a more React-centric approach, while vue-json-schema-form integrates seamlessly with Vue.js template syntax. Developers should consider their specific project requirements and preferred framework when choosing between these libraries.
Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
Pros of jsonforms
- Framework-agnostic: Works with React, Angular, and Vue
- More extensive documentation and examples
- Larger community and more frequent updates
Cons of jsonforms
- Steeper learning curve due to its flexibility
- Potentially more complex setup for simple use cases
Code Comparison
vue-json-schema-form:
<template>
<VueForm
v-model="formData"
:schema="schema"
:ui-schema="uiSchema"
/>
</template>
jsonforms:
import { JsonForms } from '@jsonforms/react';
const App = () => (
<JsonForms
data={data}
schema={schema}
uischema={uischema}
renderers={renderers}
/>
);
Both libraries use a similar approach, requiring schema and UI schema definitions. However, jsonforms offers more flexibility in terms of renderers and can be used with multiple frameworks, while vue-json-schema-form is specifically designed for Vue.js applications.
jsonforms provides a more comprehensive solution for complex form scenarios across different frameworks, but may be overkill for simpler Vue.js projects where vue-json-schema-form could be a more straightforward choice.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
vue-json-schema-form
åºäº Vue2 / Vue3ã JSON Schema çæå¸¦å®æ´æ ¡éªçForm表åï¼ä½ ç :star2: :star2: :star2: å°±æ¯æå¤§çæ¯æ
æ¥çææ¡£ - Playground - å¯è§å表åSchemaçæå¨
uiæ¡æ¶æ¯æ
交æµç¾¤
QQ群ï¼146845780
ï¼ååºä¸åæ¶ð
使ç¨é®é¢è¯·ä¼å éè¿ Github issue æäº¤
å¦ä½å¯å¨ç¸å ³ç¼è¾å¨é¡µé¢
- æ´»å¨ç¼è¾å¨é¡¹ç®å·²ç»ç¬ç«äºæ°çä»åºï¼è¯·ç´æ¥ä½¿ç¨ https://github.com/lljj-x/vjsf-demo-editor
- æ´»å¨ç¼è¾å¨é¡¹ç®å·²ç»ç¬ç«äºæ°çä»åºï¼è¯·ç´æ¥ä½¿ç¨ https://github.com/lljj-x/vjsf-demo-editor
1ã å®è£ ä¾èµ
yarn install
2ã åæ¶è¿è¡ Playground/表åSchemaçæå¨/æ´»å¨ç¼è¾å¨
# Playground http://127.0.0.1:8800/
# å¯è§å表åSchemaç¼è¾å¨ http://127.0.0.1:8800/schema-generator.html
# ï¼H5ï¼æ´»å¨ç¼è¾å¨ http://127.0.0.1:8800/vue-editor.html
yarn run demo:dev
3ã å个è¿è¡ï¼æå®entryç¼è¯æ´å¿«ï¼
# åªè¿è¡ Playground
yarn run demo:dev --dir=index
# åªè¿è¡ 表åSchemaçæå¨
yarn run demo:dev --dir=schema-generator
# åªè¿è¡ï¼H5ï¼æ´»å¨ç¼è¾å¨
yarn run demo:dev --dir=vue-editor
说æ
- éµå¾ª
JSON Schema
è§èï¼åªéè¦ç»å®JSON Schema
ï¼å³å¯çæå¯¹åºçform表å - å¿«éé 置个æ§åuiè§å¾åæ ¡éªé误信æ¯ï¼å¯éé 常ç¨çuiåº
- 表åschemaæ ¡éªä½¿ç¨ ajv
- è®¾è®¡ææ³å对schemaè§£æç´¢å¼åè react-jsonschema-form
ç¸å ³èµæ
为ä½å¼å
å¨åå端å¯è§åç¼è¾æ¶ï¼ä¸ºäºè§£å³æ°æ®é
置表åçéç¨æ§ï¼æä»¥ä½¿ç¨ JSON Schema
æè¿°æ°æ®ç»æï¼å¨æçæè¡¨åã
è¿æ ·åç好å¤é¤äºè§£å³å¨æ¯ä¸ªé 置表åçéå¤å·¥ä½ï¼æå¡ç«¯ä¹å¯ä»¥åºäºåä¸ä»½schemaä¿æåå端ä¸è´çæ ¡éªè§åï¼ä¸è¿å¯¹äºä½¿ç¨ vue elementUiå¹¶æªæ¾å°åéåºå¯ä»¥ç´æ¥ä½¿ç¨ï¼æä»¥å¨åé¢ä¸æ®µæ¶é´å³å®èªå·±å®ç°ä¸ä¸ª ã
é®é¢æå»ºè®®
æä»»ä½ä½¿ç¨é®é¢æè 建议é½å¯ä»¥éè¿ Github issue æäº¤ç»æ
License
Apache-2.0
Top Related Projects
A React component for building Web forms from JSON Schema.
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
A React library for building forms from any schema.
Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot