npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@released/vue-json-form

v1.0.0

Published

npm i @released/vue-json-form

Readme

vue-json-form

安装

npm i @released/vue-json-form

说明

基于element/ivew的表单二次封装,json数据驱动,动态创建表单

使用

  1. vue组件中引入 (必须在iview/element组件中使用,先引入iview/element组件库)
import {elmForm} from '@released/vue-json-form'  //使用element表单
import {iviewForm} from '@released/vue-json-form'  //使用iview表单
  1. 注册组件使用 form-list属性为数组
<json-form :form-list="Data" :span="24" ref="form"/>

form表单类型

type属性所有的值 | 表单类型(type) | value | | ---------------- | ---------- | | 输入框 | input | | 下拉选择 | select | | 单选 | radio | | 多选 | checkbox | | 级联选择 | cascader | | 日期选择 | datepicker | | 开关 | switch | | 自定义类型 | render |

json数据说明

| name | key | value | rules | arr | style | | -------- | ------------- | -------- | -------- | ---------------------------------------------------------------------------------------- | ------------ | | 提示文字 | 数据绑定的key | 表单的值 | 验证规则 | 需要多个数据源的时候传入的数据(如下拉选择器,统一label为显示文字,value为绑定的值) | 表单项的样式 |

data选项中配置json数据

    [
          {
            name: "render类型",
            key: "render",
            value: "",
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ],
            type: "render",
            render: function (h, item) {
              return h("Input", {
                on: {
                  "on-change": function (val) {
                    item.value = val.target.value
                  }
                },
              });
            }
          },
          {
            name: "下拉选择",
            key: "sel",
            type: "select",
            value: "",
            arr: [
              {
                label: "标签",
                value: "1"
              },
              {
                label: "标签",
                value: "2"
              }
            ],
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ]
          },
          {
            name: "多选",
            key: "check",
            type: "checkbox",
            value: [],
            arr: [
              {
                label: "标签",
                value: "1"
              },
              {
                label: "标签",
                value: "2"
              }
            ],
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ]
          },
          {
            name: "开关",
            key: "switch",
            type: "switch",
            value: [],
            rules: [
              {
                required: true,
                message: "请选择"
             }
            ]
          },
          {
            name: "单选",
            key: "radio",
            type: "radio",
            value: "",
            arr: [
              {
                label: "标签",
                value: "1"
              },
              {
                label: "标签",
                value: "2"
              },
              {
                label: "标签",
                value: "3"
              }
            ],
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ]
          },
          {
            name: "日期",
            key: "datepicker",
            type: "datepicker",
            value: "",
            dateType: "daterange",
            rules: [
              {
                type: "array",
                required: true,
                message: "请输入",
                fields: {
                  0: {
                    type: "string",
                    required: true,
                    message: "请选择起止日期"
                  }
                }
              }
            ]
          },
          {
            name: "级联",
            key: "cascader",
            type: "cascader",
            value: [],
            arr: [
              {
                label: "标签",
                value: "1",
                children: [
                  {
                    label: "标签1",
                    value: "11"
                  }
                ]
              },
              {
                label: "标签",
                value: "2"
              },
              {
                label: "标签",
                value: "3"
              }
            ],
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ]
          },
          {
            name: "输入",
            key: "input",
            value: "",
            style: {
              flexBasis: "400px"
            },
            rules: [
              {
                required: true,
                message: "请输入"
              }
            ]
          }
 ]

获取表单数据

方式1:promise方式

this.$refs.form.validate().then(res=>{
  console.log(res)
})

方式2:回调函数方式

this.$refs.form.validate((valid,res)=>{
    if(valid){
         console.log(res)
    }
})

valid为true表示验证通过 res为最终的表单数据

html中使用

script引入bundle.min 通过全局变量jsonForm.elmForm或者jsonForm.iviewForm注册json-form组件使用

注意

json-form组件可以传入iview/element的Col组件属性用来栅格布局,如span属性 span=12 表示一行显示两列表单项 默认不传span属性 span=24 每个表单项独占一行

<json-form :form-list="Data" :span="12" />