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 🙏

© 2025 – Pkg Stats / Ryan Hefner

magicbox-form-core

v1.1.0

Published

一个基于 Vue 的高度可配置表单生成组件

Readme

MagicBox Form Core

一个基于 Vue 2 和 Element UI 的高度可配置表单生成组件。

安装

npm install magicbox-form-core --save

引入

全局引入

import Vue from 'vue';
import MagicboxFormCore from 'magicbox-form-core';

Vue.use(MagicboxFormCore);

局部引入

import { MagicboxFormCore } from 'magicbox-form-core';

export default {
  components: {
    MagicboxFormCore
  }
}

基本用法

<template>
  <div>
    <magicbox-form-core 
      :renderdata="formConfig" 
      v-model="formData"
      ref="formRef"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {},
      formConfig: {
        // 表单配置
        formProps: {
          labelWidth: '120px',
          size: 'medium'
        },
        // 表单项配置列表
        itemRenderList: [
          {
            // 元素配置
            __element__: {
              tag: 'el-input',
              key: 'name',
              value: '',
              attrs: {
                placeholder: '请输入姓名'
              }
            },
            // 标签配置
            __label__: {
              label: '姓名'
            },
            // 验证规则
            __regrule__: {
              required: true,
              regList: []
            }
          }
          // 更多表单项...
        ]
      }
    };
  },
  methods: {
    // 表单验证
    validateForm() {
      this.$refs.formRef.validate((valid, invalidFields) => {
        if (valid) {
          console.log('表单验证通过', this.formData);
        } else {
          console.log('表单验证失败', invalidFields);
        }
      });
    }
  }
}
</script>

组件属性

| 属性名 | 说明 | 类型 | 默认值 | |------|------|------|------| | renderdata | 表单渲染配置对象 | Object | {} | | value | 表单数据对象 (v-model) | Object | {} | | parentInstance | 父组件实例 | Object | null |

组件方法

| 方法名 | 说明 | 参数 | |------|------|------| | validate | 表单验证 | callback(Function) - 验证完成后的回调函数 |

配置说明

renderdata 对象结构

{
  // 表单属性配置
  formProps: {
    labelWidth: '120px',  // 标签宽度
    size: 'medium'        // 尺寸大小,可选值:medium / small / mini
    // 其他 el-form 支持的属性...
  },
  
  // 表单项列表
  itemRenderList: [
    {
      // 元素配置
      __element__: {
        tag: 'el-input',     // 使用的 Element UI 组件名称
        key: 'fieldName',    // 字段名,对应 formData 中的属性
        value: '',           // 默认值
        attrs: {             // 传递给组件的属性
          placeholder: '请输入'
          // 其他组件属性...
        }
      },
      
      // 标签配置
      __label__: {
        label: '字段名称'  // 表单项标签文本
      },
      
      // 验证规则
      __regrule__: {
        required: true,     // 是否必填
        regList: [          // 验证规则列表
          {
            pattern: '/^\\w+$/',  // 正则表达式
            message: '格式不正确'  // 错误提示
          }
          // 更多规则...
        ]
      },
      
      // 插槽占位符配置(可选)
      slot: 'slotName',
      __slotRules__: {
        prop: 'slotFieldName',  // 插槽字段名
        rules: [                // 验证规则
          { required: true, message: '不能为空' }
        ]
      }
    }
    // 更多表单项...
  ]
}

注意事项

  1. 组件依赖 Vue 2.6+ 和 Element UI 2.15+
  2. 请确保 Element UI 已正确安装并注册
  3. 表单验证规则遵循 Element UI 的表单验证规则格式