### Array Configuration Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/array.md This example demonstrates various `uiSchema` configurations for array fields, including custom widgets, item options, and toolbar settings. ```json { schema: { type: 'object', properties: { listOfString: { type: 'array', title: 'List of strings', items: { type: 'string', default: 'lorem ipsum' } }, multipleChoicesList: { type: 'array', title: 'Multiple Choices', items: { type: 'string', enum: ['foo', 'bar'] }, default: ['foo', 'bar'] }, fixedItemsList: { type: 'array', title: 'Fixed Items', items: [ { title: 'A string', type: 'string', default: 'lorem ipsum' }, { title: 'A boolean', type: 'boolean', default: false, }, ], additionalItems: { title: 'A string', type: 'string', default: 'lorem ipsum' }, }, } }, uiSchema: { listOfString: { items: { name: { 'ui:options': { placeholder: 'Please enter a name' } } } }, multipleChoicesList: { 'ui:widget': 'CheckboxesWidget' }, fixedItemsList: { items: [ { 'ui:options': { type: 'textarea' } }, { 'ui:options': { activeText: '开', inactiveText: '关' } }, { 'ui:options': { placeholder: 'Please enter' } } ], additionalItems: { 'ui:options': { step: 10 } } }, unorderable: { 'ui:options': { sortable: false, }, }, unremovable: { 'ui:options': { removable: false, }, }, noToolbar: { 'ui:options': { addable: false, sortable: false, removable: false, }, items: { 'ui:options': { title: '不显示操作条' } } }, fixedNoToolbar: { 'ui:options': { addable: false, sortable: false, removable: false, }, }, }, errorSchema: { nestedList: { items: { items: { 'err:required': '请输入Inner item name' } } } }, formData: { multipleChoicesList: ['foo', 'bar'], fixedItemsList: ['Some text', true], nestedList: [['lorem', 'ipsum'], ['dolor']], unorderable: ['one', 'two'], unremovable: ['one', 'two'], noToolbar: ['one', 'two'], fixedNoToolbar: [42, true, 'additional item one', 'additional item two'], } } ``` -------------------------------- ### Install Vue JSON Schema Form Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/README.md Install the library using npm or yarn. Choose the appropriate version based on your Vue and UI framework setup. ```bash # 安装 # vue2+elementUi 版本 npm install --save @lljj/vue-json-schema-form element-ui # 或者: yarn add @lljj/vue-json-schema-form ``` -------------------------------- ### Install Vue JSON Schema Form Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/en/guide/README.md Install the library using npm or yarn package managers. ```bash # npm npm install --save @lljj/vue-json-schema-form ``` ```bash # yarn yarn add @lljj/vue-json-schema-form ``` -------------------------------- ### CheckboxesWidget Usage Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/lib/vue3/vue3-form-element/src/config/widgets/CheckboxesWidget/readme.md This is a basic JavaScript example demonstrating the usage of console.log. It is part of the CheckboxesWidget documentation. ```javascript console.log(1); ``` -------------------------------- ### Install @lljj/vue-json-schema-form via npm Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/README.md Use npm to install the core Vue JSON Schema Form package. This is the recommended method for most projects. ```bash npm install --save @lljj/vue-json-schema-form ``` ```bash yarn add @lljj/vue-json-schema-form ``` -------------------------------- ### Schema and Form Data Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/design.md An example illustrating a JSON schema for an object with properties and a corresponding partial `formData`. This is used to demonstrate how the schema is broken down for validation. ```json schema = { type: 'object', minProperties: 2, required: [ 'firstName', 'lastName' ], properties: { firstName: { type: 'string', title: 'First name', default: 'Jun' }, lastName: { type: 'string', title: 'Last name' } } }; formData = { firstName: 'Jun' } ``` -------------------------------- ### Layout Demonstration with Multiple Configurations Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/layout-config.md This example demonstrates a form with a 2-column layout applied globally via `formProps.layoutColumn`. Additionally, individual items within 'Object2' are configured with specific widths (33.333%) using `ui:options.width` to showcase mixed layout strategies. ```html ``` -------------------------------- ### Custom Widget Example with Render Function Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/adv-config.md This example demonstrates creating a custom widget using Vue's render function. The widget updates its value when a button is clicked and displays the current value. It's configured in `uiSchema` to replace the default input for the 'inputText' field. ```html ``` -------------------------------- ### UploadWidget with Custom Slots Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/components.md Demonstrates how to customize the UploadWidget's appearance and behavior using the `ui:slots` property. This example shows how to replace the default upload button and add custom tip text using VNode objects. ```html ``` -------------------------------- ### Object Schema and Validation Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/object.md Demonstrates the usage of an object schema with nested properties and validation rules. It shows how to configure additionalProperties to false for a specific object and how error schemas can be used to display custom error messages. ```html ``` -------------------------------- ### Configure Form Layout Columns Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/layout-config.md Set the `layoutColumn` prop in `formProps` to define the number of columns for the entire form. This example sets the form to a 2-column layout. ```js formProps: { layoutColumn: 2 } ``` -------------------------------- ### Configure Field Attributes and Widget Properties Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/basic-config.md Configure UI schema to pass attributes to the Field component and properties to the Widget component. This example shows how to set a placeholder and type for a textarea widget. ```json { "ui:field": true, "fieldAttrs": { "attr-x": "xxx" }, "type": "textarea", "placeholder": "请输入你的内容" } ``` -------------------------------- ### allOf Example: Merging Schemas Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/combining.md Demonstrates the use of `allOf` to combine multiple schemas. Properties from all schemas are merged. If schemas cannot be merged (e.g., string and number types), the data will always be invalid. ```javascript schema = { "allOf": [ { "type": "string" }, { "type": "number" } ] } ``` -------------------------------- ### Handling Required Properties in Rendering Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/design.md A pseudocode example demonstrating how the `required` status for a property is determined and passed down to child components during rendering. This is crucial for correctly applying validation and UI feedback. ```javascript //伪代码 - required 通过父节点传递props function render(h) { const propertiesVnode = propertiesNameList.map(name => { return h( ChildField, { props: { ..., required: Array.isArray(schema.required) && schema.required.includes(name), } } ); }); } ``` -------------------------------- ### Boolean Type Configuration Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/boolean.md Configure a boolean field with custom active and inactive text labels using ui-options. This example demonstrates how to set up the schema, ui-schema, and error-schema for a boolean input. ```html ``` -------------------------------- ### User Info Form Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/basic-config.md A complete Vue component demonstrating a user information form. It utilizes the `vue-form` component with a defined `schema` prop to structure the form fields, including types, titles, and validation rules like required fields, minimum/maximum values, and minimum length. ```html ``` -------------------------------- ### UI-Schema Expression Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/basic-config.md Demonstrates using mustache expressions within ui-schema for conditional rendering based on parent form data. Supports `parentFormData` and `rootFormData` variables. ```javascript 'ui:title': `{{ parentFormData.age > 18 ? '呵呵呵' : '嘿嘿嘿' }}` ``` -------------------------------- ### Vue Form with Number and Integer Schema Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/number.md This example demonstrates a Vue form with schema configurations for integer (age) and number (price) types, including minimum, maximum, multipleOf, and enum validation. ```html ``` -------------------------------- ### Vue Form with anyOf for Data Linkage Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/data-linkage.md Demonstrates using 'anyOf' to conditionally render form fields based on selected options. This example shows how to set personal information via username or user ID. Click 'Save' to view the formData. ```html ``` -------------------------------- ### Custom Rule with Regex Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/validate.md Use regular expressions within custom rules to validate multiple array items or fields matching a pattern. This example demonstrates validating all 'imgUrl' fields within the 'imgList' array. ```javascript // 这里可以选择你喜欢的方法找到你要校验的节点 // 比如匹配:imgList.0.imgUrl imgList.1.imgUrl ... if (/imgList\.\d+\.imgUrl/.test(field)) { return callback('永远校验失败'); } ``` -------------------------------- ### anyOf Data Backfilling with const Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/combining.md Demonstrates how to use `const` within `anyOf` schema options to ensure correct data matching during backfilling. This is particularly useful when different `anyOf` branches share similar data structures. ```javascript const schema = { type: 'object', title: '选项', required: [], anyOfSelect: { 'ui:title': '渲染组件' }, anyOf: [{ title: 'el-switch', type: 'object', properties: { schemaOptions: { type: 'object', properties: { 'ui:widget': { title: '使用组件', type: 'string', default: 'el-switch', const: 'el-switch', 'ui:hidden': true }, other: { title: '其它', type: 'string' } } } } }, { title: 'el-checkbox组件', type: 'object', properties: { schemaOptions: { type: 'object', properties: { 'ui:widget': { title: '使用组件', type: 'string', default: 'el-checkbox', const: 'el-checkbox', 'ui:hidden': true }, other: { title: '其它', type: 'string' } } } } }] } ``` -------------------------------- ### Null Type Schema Configuration Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/null.md This example shows how to define a schema with a 'null' type property. The 'null' type field is not rendered, and the formData will have a null value for this property. ```html ``` -------------------------------- ### Widget Props from Schema Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/number.md The component passes props to the Widget based on schema configuration. For example, `multipleOf` sets the step, and `minimum`/`maximum` set the min/max values. ```javascript const props = {}; if (undefined !== schema.multipleOf) { // 组件计数器步长 props.step = schema.multipleOf; } if (schema.minimum || schema.minimum === 0) { props.min = schema.minimum; } if (schema.maximum || schema.maximum === 0) { props.max = schema.maximum; } ``` -------------------------------- ### Using anyOf with const and uiSchema Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/combining.md Demonstrates how `const` values within `anyOf` are rendered as radio buttons, with `const` as the value and `title` as the label. It also shows how `uiSchema` can override or provide additional titles for these options. Common configurations for `anyOf` siblings are passed to the selected sub-schema. ```html ``` -------------------------------- ### 手动按需导入 `core-js` 模块 Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/polyfill.md 如果 `@babel/polyfill` 导入的垫片不够全,可以手动按需导入缺失的API,例如导入 `Promise` 支持。 ```javascript // 比如提示缺失 Promise import 'core-js/modules/es6.promise'; ``` -------------------------------- ### Conditional Rendering with Mustache Expression Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/data-linkage.md Use 'ui:hidden' with a Mustache expression to conditionally hide a field based on parent form data. This example hides the 'league' field if 'parentFormData.attr' is not 'league'. ```json { "type": "object", "properties": { "league": { "type": "string", "title": "联赛", "enum": [ "西甲", "英超", "中超" ], "ui:hidden": "{{parentFormData.attr !== 'league'}}", "ui:width": "40%" } } } ``` -------------------------------- ### 配置表单页脚按钮文字 Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/i18n.md 通过 `formFooter` 对象配置确认和取消按钮的文字。 ```javascript formFooter = { okBtn: 'Save', // 确认按钮文字 cancelBtn: 'Cancel' // 取消按钮文字 } ``` -------------------------------- ### UI Schema Order Configuration Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/rules/object.md Illustrates how to control the rendering order of object properties using the 'ui:order' property within the ui-schema. The '*' wildcard can be used to include all other properties not explicitly listed. ```javascript uiSchema = { 'ui:order': ['number', '*'], // 'ui:order': ['firstName', 'lastName'], } ``` -------------------------------- ### 配置表单项的 UI Schema 多语言 Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/i18n.md 通过 `ui-schema` 配置表单项的 `title` 等属性,并结合项目自身的翻译方法实现多语言。 ```html ``` -------------------------------- ### UI Schema Array Item Configuration Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/basic-config.md Illustrates the correct way to configure UI schema for array items, emphasizing that the structure should mirror the schema's item structure, not the formData. ```js // schema schema = { type: 'object', properties: { fixedItemsList: { type: 'array', title: 'A list of fixed items', items: [ { title: 'A string value', type: 'string', maxLength: 2 } ] } } } ``` ```js // 正确的配置 uiSchema = { fixedItemsList: { // 这里保持和 schema 结构相同 items: [ { 'ui:options': { ... } } ] } } ``` ```js // 错误的配置 uiSchema = { fixedItemsList: [ { 'ui:options': { ... } } ] } ``` -------------------------------- ### Configure Individual Form Item Width Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/layout-config.md Specify the `ui:width` in the `ui-schema` for a specific form item to control its width. Any valid CSS width value can be used. This example sets an item's width to 50%. ```js 'ui:width': { width: '50%' } ``` -------------------------------- ### Get and Set Form Data Path Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/design.md Utility functions for accessing and modifying nested form data using a path string. Useful for managing high-frequency changes in `formData` without re-rendering the entire component tree. ```javascript import { vueUtils } from '@lljj/vue-json-schema-form'; // get vueUtils.getPathVal(rootFormData, curNodePath); // set vueUtils.setPathVal(rootFormData, curNodePath, value); ``` -------------------------------- ### Integrating Custom Province-City-Area Component Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/adv-config.md Demonstrates embedding a custom province-city-area linkage component using 'ui:field'. It configures placeholder text for the custom component via 'ui:fieldProps'. This example omits the component import and registration code. ```html ``` -------------------------------- ### 动态配置 SelectWidget 的 ui:enumOptions Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/faq.md 演示如何通过动态更新 `uiSchema` 中的 `ui:enumOptions` 来动态配置下拉选择框的选项。适用于需要根据异步数据或用户交互改变选项的场景。 ```html ``` -------------------------------- ### Custom Rule Function Example Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/validate.md Define a custom rule function to validate specific fields based on their path and value. This function receives field path, current value, root form data, and a callback. Use a callback with an error message to indicate validation failure. ```javascript const customRule = ({ field, value, rootFormData, callback }) => { if (field === 'imgList.0.imgUrl') { return callback('永远校验失败'); } return callback(); }; ``` -------------------------------- ### Babel-Loader 配置 `include` Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/zh/guide/polyfill.md 如果项目使用 `babel-loader`,可以通过配置 `include` 选项来指定需要转译的库文件目录,包括 `@lljj/vue-json-schema-form`。请根据实际项目情况调整路径。 ```javascript { test: /\.js$/ loader: 'babel-loader', include: [ path.resolve(__dirname,'../src'), path.resolve(__dirname,'../node_modules/@lljj/vue-json-schema-form') // + 添加这一行 ] } ``` -------------------------------- ### Basic Vue Form Component Usage Source: https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/docs/docs/README.md Demonstrates how to use the VueForm component in a Vue application. It requires importing the component and configuring schema and uiSchema data. ```vue ```