最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • 基于 Vue 3.x 的 Form render

    正文概述 掘金(muwoo)   2021-01-13   440

    基于 Vue 3.x 的 Form render

    github: vue form render

    在线演示

    简介

    我们在写一些常规后台页面的时候,避免不了是需要经常和表单打交道。所以可以想偷懒的小伙伴可能会考虑有没有办法不去做表单工程师?用代码解决重复的人肉工作,没错,我们可以通过 JSON Schema 来描述我们的表单信息,这比重复的写表单控件可方便多了。

    但是 JSON Schema 到表单的映射,则是需要我们去关注的,so... 业界有没有比较好的方案呢?答案是肯定的,比如以下几个表单渲染工具:

    • Form Render
    • Formliy
    • ...

    Formliy 是一款比较强大的表单渲染器,目前对 React 支持最友好,Vue 相关的有一个 vue-formly 但也仅仅是 Vue 2.x 的。还有就是 Formliy 过于强大,不仅仅支持 JSON Schema 还支持 JSX Schema 渲染表单。而我们只是单纯需要像 Form Render 这样的 JSON Schema 标准的轻量易用型框架。

    所以 有了这个 基于 Vue 3.x 的 Form render

    功能

    vue-form-render 是基于 Form Render 基本能力作为原型实现的 Vue 3.x 版本的表单渲染器,目前支持 90% 左右的 Form Render 功能,后续会不断的维护支持。

    使用demo

    <template>
      <div>
        <formRender
          :schema="schema"
          :formData="formData"
          @on-change="change"
          @on-validate="validate"
        />
      </div>
    </template>
    
    <script>
    import {reactive, toRefs} from 'vue';
    
    // render index
    import FormRender from 'kaer-form-render';
    // form render style
    import 'kaer-form-render/lib/kaer-form-render.css';
    
    export default {
      name: 'App',
      setup() {
        const state = reactive({
          schema: {
            type: 'object',
            properties: {
              string: {
                title: 'string',
                type: 'string',
                maxLength: 4,
              }
            },
          },
          formData: {
            string: 'aaa'
          },
        });
    
        const change = (v) => {
          state.formData = v;
          console.log(v);
        }
        const validate = (v) => {
          console.log(v);
        }
    
        return {
          ...toRefs(state),
          change,
          validate,
        }
      },
      components: {
        FormRender,
      }
    }
    </script>
    
    

    Array

    • 支持excel导入数据,方便快快捷生成form Data
    • 支持拖拽排序
    "listName2": {
      "title": "对象数组",
      "description": "对象数组嵌套功能",
      "type": "array",
      "minItems": 1,
      "maxItems": 3,
      "ui:displayType": "row",
      "items": {
        "type": "object",
        "properties": {
          "input1": {
            "title": "简单输入框",
            "type": "string"
          },
          "selet1": {
            "title": "单选",
            "type": "string",
            "enum": [
              "a",
              "b",
              "c"
            ],
            "enumNames": [
              "早",
              "中",
              "晚"
            ]
          }
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    string

     "string": {
      "title": "字符串",
      "type": "string",
      "maxLength": 4,
      "ui:options": {
        "placeholder": "试着输入超过4个字符"
      }
    }
    

    基于 Vue 3.x 的 Form render

    color-picker

     "color": {
      "title": "颜色选择",
      "type": "string",
      "format": "color"
    }
    

    基于 Vue 3.x 的 Form render

    date-picker

     "date": {
      "title": "日期选择",
      "type": "string",
      "format": "date"
    }
    

    基于 Vue 3.x 的 Form render

    image

    "image": {
      "title": "图片展示",
      "type": "string",
      "format": "image"
    }
    

    基于 Vue 3.x 的 Form render

    number

    "allNumber": {
      "title": "number类",
      "type": "object",
      "properties": {
        "number1": {
          "title": "数字输入框",
          "description": "1 - 1000",
          "type": "number",
          "min": 1,
          "max": 1000
        },
        "number2": {
          "title": "带滑动条",
          "type": "number",
          "ui:widget": "slider"
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    boolean

    "allBoolean": {
      "title": "boolean类",
      "type": "object",
      "properties": {
        "radio": {
          "title": "是否通过",
          "type": "boolean"
        },
        "switch": {
          "title": "开关控制",
          "type": "boolean",
          "ui:widget": "switch"
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    date-range

     "allRange": {
      "title": "range类",
      "type": "object",
      "properties": {
        "dateRange": {
          "title": "日期范围",
          "type": "range",
          "format": "dateTime",
          "ui:options": {
            "placeholder": [
              "开始时间",
              "结束时间"
            ]
          }
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    emun

     "allEnum": {
      "title": "选择类",
      "type": "object",
      "properties": {
        "select": {
          "title": "单选",
          "type": "string",
          "enum": [
            "a",
            "b",
            "c"
          ],
          "enumNames": [
            "早",
            "中",
            "晚"
          ]
        },
        "radio": {
          "title": "单选",
          "type": "string",
          "enum": [
            "a",
            "b",
            "c"
          ],
          "enumNames": [
            "早",
            "中",
            "晚"
          ],
          "ui:widget": "radio"
        },
        "multiSelect": {
          "title": "多选",
          "description": "下拉多选",
          "type": "array",
          "items": {
            "type": "string"
          },
          "enum": [
            "A",
            "B",
            "C",
            "D"
          ],
          "enumNames": [
            "杭州",
            "武汉",
            "湖州",
            "贵阳"
          ],
          "ui:widget": "multiSelect"
        },
        "boxes": {
          "title": "多选",
          "description": "checkbox",
          "type": "array",
          "items": {
            "type": "string"
          },
          "enum": [
            "A",
            "B",
            "C",
            "D"
          ],
          "enumNames": [
            "杭州",
            "武汉",
            "湖州",
            "贵阳"
          ]
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    Object

    "obj1": {
      "title": "可折叠对象",
      "description": "这是个对象类型",
      "type": "object",
      "ui:options": {
        "collapsed": true
      },
      "properties": {
        "input1": {
          "title": "输入框1",
          "type": "string"
        },
        "input2": {
          "title": "输入框2",
          "type": "string"
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    rich-text

    {
      "type": "object",
      "properties": {
        "content": {
          "title": "富文本编辑器",
          "type": "string",
          "format": "richText"
        }
      }
    }
    

    基于 Vue 3.x 的 Form render

    API

    Props

    参数说明类型默认值
    schameJSON Schemaobject--formData表单的数据object--

    Events

    事件名说明回调函数
    on-change用户触发表单更新的回调函数function(value: formData)on-validate用户触发表单更新的校验回调函数function(value: validates)

    最后

    欢迎大家使用并pr,我们一起打造一款好用的vue form render

    github: vue form render

    在线演示


    起源地下载网 » 基于 Vue 3.x 的 Form render

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元