Giter VIP home page Giter VIP logo

scrooge-vue3-json-schema-form's Introduction

An UI-component library based on Vue3

API 设计

<JsonSchemaForm
  schema={schema}
  value={value}
  onChange={handleOnChange}
  locale={locale}
  contextRef={someRef}
  uiSchema={uiSchema}
/>

schema

json schema 对象,用来定义数据,同事也是定义表单的依据

value

表单的数据结果,你可以从外部改变这个value,在表单被编辑的时候,会通过onChange透出value

需要注意的一点,因为vue使用的是可变数据,如果每次数据变化我们都去改变value的对象地址,那么会导致整个表单都需要重新渲染,从而造成大量的性能浪费。 从实践中来看,我们传入的对象,在内部修改其field的值基本不会有什么副作用,所以我们会使用这种方式来进行实现。也就是说,如果value是一个对象,那么从JsonSchemaForm内部修改的值,并不会改变value对象本身,我们仍然会触发onChange,因为可能在表单变化之后,用户需要进行进一步的操作。

onChange

在表单值发生变化的时候会触发该回调函数,并把新的值返回

locale

语言,使用ajv-i18n指定错误信息使用的语言

contextRef

你需要传入一个vue3Ref对象,我们会在这个对象上挂载doValidate方法,你可以通过

const yourRef = ref({});

onMounted(() => {
  yourRef.value.doValidate();
});

<JsonSchemaForm contextRef={yourRef} />;

这样来主动对表单进行校验。

uiSchema

对表单的展示进行一些定制,其类型如下:

export interface VueJsonSchemaConfig {
  title?: string;
  description?: string;
  component?: string;
  additionProps?: {
    [key: string]: any;
  };
  withFormItem?: boolean;
  widget?: "checkbox" | "textarea" | "select" | "radio" | "range" | string;
  items?: UISchema | UISchema[];
}
export interface UISchema extends VueJsonSchemaConfig {
  properties?: {
    [property: string]: UISchema;
  };
}

scrooge-vue3-json-schema-form's People

Contributors

scrooge-yn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.