@dzikoysk/vue-vanilla

中文文档
3.4.1发布于 2024/11/22MITTypeScriptESM + CJS近 30 天下载 3161

Vue 3 Vanilla renderers for JSON Forms

原始使用文档
文档目录7 节
  1. Vue Vanilla Renderers
  2. JSON Forms Vue seed app
  3. Quick start
  4. Styling
  5. License
  6. Roadmap
  7. Migration

JSON Forms - More Forms. Less Code

Complex Forms in the blink of an eye

JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript.

Vue Vanilla Renderers

This is the JSON Forms Vue Vanilla renderers package which provides a HTML5-based renderer set for JSON Forms Vue.

JSON Forms Vue seed app

See our JSON Forms Vue seed repository to get started as quickly as possible.

Quick start

Install JSON Forms Core, Vue and Vue Vanilla Renderers

npm i --save @jsonforms/core @jsonforms/vue @jsonforms/vue-vanilla

Also add the packages to the transpile dependencies in the vue.config.js file:

module.exports = {
  transpileDependencies: [
    '@jsonforms/core',
    '@jsonforms/vue',
    '@jsonforms/vue-vanilla',
  ],
};

Use the json-forms component for each form you want to render and hand over the renderer set.

<script>
import { JsonForms } from '@jsonforms/vue';
import { vanillaRenderers } from '@jsonforms/vue-vanilla';
import { defineComponent } from 'vue';

const renderers = [
  ...vanillaRenderers,
  // here you can add custom renderers
];

export default defineComponent({
  components: {
    JsonForms,
  },
  data() {
    return {
      renderers: Object.freeze(renderers),

      data: {
        number: 5,
      },
      schema: {
        properties: {
          number: {
            type: 'number',
          },
        },
      },
      uischema: {
        type: 'VerticalLayout',
        elements: [
          {
            type: 'Control',
            scope: '#/properties/number',
          },
        ],
      },
    };
  },
  methods: {
    onChange(event) {
      this.data = event.data;
    },
  },
});
</script>
<template>
  <json-forms
    :data="data"
    :schema="schema"
    :uischema="uischema"
    :renderers="renderers"
    @change="onChange"
  />
</template>

By default the Vanilla Renderers don't apply any CSS at all. For a quick start you can use @jsonforms/vue-vanilla/vanilla.css.

For more information on how JSON Forms can be configured, please see the README of @jsonforms/vue.

Styling

Each rendered HTML element specifies a CSS class which can be used to style it. This process can also be customized so that each element declares user-specified CSS classes. Therefore JSON Forms Vue Vanilla can be integrated with any CSS-only UI framework quite easily.

You can find the default CSS classes in `defaultStyles.ts.

To render your own classes simply provide them as styles. These styles replace the defaultStyles. If you want to fall back to defaultStyles or combine them with your own classes you'll need to do so programmatically, e.g.:

<script>
import { JsonForms } from '@jsonforms/vue';
import {
  defaultStyles,
  mergeStyles,
  vanillaRenderers,
} from '@jsonforms/vue-vanilla';
import { defineComponent } from 'vue';

// mergeStyles combines all classes from both styles definitions
const myStyles = mergeStyles(defaultStyles, {
  control: { root: 'my-control' },
});

export default defineComponent({
  name: 'app',
  components: {
    JsonForms,
  },
  data() {
    return {
      renderers: Object.freeze(vanillaRenderers),
      data: {
        number: 5,
      },
      schema: {
        properties: {
          number: {
            type: 'number',
          },
        },
      },
      uischema: {
        type: 'VerticalLayout',
        elements: [
          {
            type: 'Control',
            scope: '#/properties/number',
          },
        ],
      },
    };
  },
  methods: {
    onChange(event) {
      this.data = event.data;
    },
  },
  provide() {
    return {
      styles: myStyles,
    };
  },
});
</script>
<template>
  <json-forms
    :data="data"
    :schema="schema"
    :uischema="uischema"
    :renderers="renderers"
    @change="onChange"
  />
</template>

You can also use specify styles in the ui schema via the options.styles property. Attributes specified here override the respective defaultStyles or provided styles. Attributes not specified here fall back to either the defaultStyles or provided styles.

{
  "type": "Control",
  "scope": "#/properties/name",
  "options": {
    "styles": {
      "control": {
        "root": "my-control-root"
      }
    }
  }
}

License

The JSONForms project is licensed under the MIT License. See the LICENSE file for more information.

Roadmap

Our current roadmap is available here.

Migration

See our migration guide when updating JSON Forms.

版本与发布记录

@dzikoysk/vue-vanilla 共发布 11 个版本,首次发布于 2022/05/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.4.1latest2024/11/222 年前
3.1.12024/11/222 年前
3.1.02023/07/023 年前
3.0.02022/10/314 年前
3.0.0-rc.12022/09/064 年前
3.0.0-beta.22022/05/184 年前

关于 @dzikoysk/vue-vanilla 的常见问题

@dzikoysk/vue-vanilla 是什么?

Vue 3 Vanilla renderers for JSON Forms

如何安装 @dzikoysk/vue-vanilla?

在项目目录运行 npm install @dzikoysk/vue-vanilla,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@jsonforms/core(3.4.1)、@jsonforms/vue(3.4.1)、vue(^3.2.26)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dzikoysk/vue-vanilla 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dzikoysk/vue-vanilla 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dzikoysk/vue-vanilla 可以商用吗?

@dzikoysk/vue-vanilla 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dzikoysk/vue-vanilla 的下载量有多少?

根据 npm 官方下载统计,@dzikoysk/vue-vanilla 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,161 次,日均约 105 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dzikoysk/vue-vanilla 还在维护吗?

最新版本 3.4.1 发布于 2024/11/22(2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/05/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。