Convert Figma logo to code with AI

lljj-x logovue-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

2,139
432
2,139
29

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:

  1. Install the library using npm or yarn:
npm install vue-json-schema-form
  1. 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

  1. Framework: vue-json-schema-form is specifically designed for Vue.js, while jsonform is more framework-agnostic.
  2. Syntax: vue-json-schema-form uses Vue component syntax, whereas jsonform uses jQuery-style initialization.
  3. Customization: vue-json-schema-form offers more fine-grained control over form rendering through ui-schema.
  4. Performance: vue-json-schema-form likely has better performance due to Vue.js reactivity system.
  5. 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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vue-json-schema-form

基于 Vue2 / Vue3、 JSON Schema 生成带完整校验的Form表单,你的 :star2: :star2: :star2: 就是最大的支持

查看文档 - Playground - 可视化表单Schema生成器

ui框架支持

交流群

QQ群:146845780,反应不及时🙄

使用问题请优先通过 Github issue 提交

如何启动相关编辑器页面

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 | Vue

为何开发

在做前端可视化编辑时,为了解决数据配置表单的通用性,所以使用 JSON Schema 描述数据结构,动态生成表单。

这样做的好处除了解决在每个配置表单的重复工作,服务端也可以基于同一份schema保持和前端一致的校验规则,不过对于使用 vue elementUi并未找到合适库可以直接使用,所以在后面一段时间决定自己实现一个 。

问题或建议

有任何使用问题或者建议都可以通过 Github issue 提交给我

License

Apache-2.0

NPM DownloadsLast 30 Days