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

schema-ui-vue

v0.1.2

Published

JSON Schema driven form generator for Vue 3. Pass a schema, get a form.

Downloads

32

Readme

schema-ui-vue

JSON Schema → Vue 表单,自动生成配置界面。

CI npm license

传入一个 JSON Schema,自动渲染对应的表单控件(文本框、数字输入、复选框、下拉框、文本域、数组列表)。支持嵌套对象、实时验证、多列布局,可嵌入任意 Vue 3 页面。


快速开始

npm install schema-ui-vue
<template>
  <AutoConfigForm :schema="schema" v-model="config" />
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { AutoConfigForm } from 'schema-ui-vue'
import 'schema-ui-vue/style.css'

const schema = {
  type: 'object',
  properties: {
    host:  { type: 'string',  title: '主机',    default: 'localhost' },
    port:  { type: 'integer', title: '端口',    default: 8080 },
    debug: { type: 'boolean', title: '调试模式', default: false },
    level: { type: 'string',  title: '日志级别', enum: ['debug', 'info', 'warn', 'error'] },
  },
  required: ['host', 'port'],
}

const config = ref({})
</script>

Schema → 控件对照表

| JSON Schema 类型 | 条件 | 渲染控件 | |------------------|------|---------| | boolean | — | 复选框 | | number / integer | — | 数字输入框 | | string | 有 enum 字段 | 下拉选择框 | | string | format: "textarea" | 多行文本域 | | string | 其他 | 单行文本框 | | array | items.type: "string" | 字符串列表(可增删) | | array | items.type: "integer"/"number" | 数字列表(可增删) | | object | 有 properties | 分组(<fieldset>,支持递归嵌套) |


API

Props

| Prop | 类型 | 默认值 | 说明 | |------|------|--------|------| | schema | JsonSchema | — | Schema 对象(与 schemaUrl 二选一) | | schemaUrl | string | — | Schema 文件 URL,组件自动 fetch | | modelValue | Record<string, unknown> | — | v-model 绑定,双向同步配置数据 | | columns | number | 2 | 每行显示几列控件(1 / 2 / 3) | | showToolbar | boolean | false | 显示工具栏(验证、重置、导出 JSON、列数切换) | | showPreview | boolean | false | 右侧显示实时 JSON 预览面板 |

Emits

| 事件 | 参数 | 说明 | |------|------|------| | update:modelValue | Record<string, unknown> | 任意字段变更时触发 |

暴露方法(通过 ref 调用)

| 方法 | 返回值 | 说明 | |------|--------|------| | validate() | ValidationResult | 用 ajv 验证当前配置,返回 { valid, errors } | | reset() | void | 重置为 Schema 默认值,并触发 update:modelValue |

<AutoConfigForm ref="formRef" :schema="schema" v-model="config" />

<script setup lang="ts">
const formRef = ref()

function save() {
  const { valid, errors } = formRef.value.validate()
  if (!valid) {
    console.log('验证失败', errors)
    return
  }
  // 提交 config.value ...
}
</script>

使用示例

嵌入页面局部区域

<template>
  <div class="settings-panel">
    <h3>服务器配置</h3>
    <AutoConfigForm
      :schema="serverSchema"
      v-model="serverConfig"
      :columns="2"
      :show-toolbar="true"
    />
    <button @click="save">保存</button>
  </div>
</template>

从 URL 加载 Schema

<!-- 组件自动 fetch,支持 watch schemaUrl 变化 -->
<AutoConfigForm
  schema-url="/api/config-schema.json"
  v-model="config"
  :show-preview="true"
/>

监听变更(实时保存)

<AutoConfigForm
  :schema="schema"
  v-model="config"
  @update:model-value="autosave"
/>

手动触发验证并高亮错误

<AutoConfigForm ref="form" :schema="schema" v-model="config" />
<button @click="form.validate()">提交前验证</button>

类型导出

import type {
  JsonSchema,           // JSON Schema 接口
  FormFieldDescriptor,  // 字段描述符(用于自定义扩展)
  ValidationResult,     // { valid: boolean; errors: ValidationError[] }
  ValidationError,      // { path: string; message: string }
  ControlType,          // 'text' | 'number' | 'checkbox' | 'select' | 'textarea' | 'array' | 'group'
} from 'schema-ui-vue'

开发

# 克隆项目
git clone https://github.com/liyixin123/schema-ui-vue.git
cd schema-ui-vue
npm install

npm run dev            # 启动 demo 开发服务器
npm test               # 运行测试
npm run test:coverage  # 查看覆盖率报告
npm run build:lib      # 构建组件库到 dist-lib/
npm run build          # 构建 demo 应用到 dist/

项目结构

src/
├── components/
│   ├── AutoConfigForm.vue   # 对外 API:主组件
│   ├── FormRenderer.vue     # 动态渲染字段列表
│   ├── FieldWrapper.vue     # 字段标签 + 描述 + 错误展示
│   ├── FieldGroup.vue       # 嵌套对象 fieldset(递归)
│   ├── ConfigToolbar.vue    # 工具栏
│   ├── ConfigPreview.vue    # JSON 预览面板
│   └── controls/            # TextInput / NumberInput / CheckboxInput / SelectInput / TextareaInput / ArrayInput
├── composables/
│   ├── useFormState.ts      # 不可变状态管理
│   └── useValidation.ts     # ajv 验证 + 错误映射
├── utils/
│   ├── schema-parser.ts     # JsonSchema → FormFieldDescriptor[]
│   ├── default-values.ts    # 提取 Schema 默认值
│   └── deep-clone.ts        # setNestedValue / getNestedValue(不可变更新)
├── types/                   # TypeScript 接口定义
└── index.ts                 # 库入口(导出组件 + 类型)

License

MIT