
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
element-plus-dynamic-form-test
Advanced tools
一个基于 Element Plus 的强大动态表单组件库,支持拖拽式表单构建器和丰富的字段类型。
npm install element-plus-dynamic-form
<template>
<DynamicForm :config="formConfig" @submit="handleSubmit" @field-change="handleFieldChange" />
</template>
<script setup>
import { DynamicForm } from 'element-plus-dynamic-form'
import { builtinRules } from 'element-plus-dynamic-form'
const formConfig = {
fields: [
{
prop: 'name',
label: '姓名',
type: 'input',
placeholder: '请输入姓名',
required: true,
rules: [builtinRules.required('请输入姓名')]
},
{
prop: 'email',
label: '邮箱',
type: 'input',
placeholder: '请输入邮箱',
required: true,
rules: [builtinRules.required('请输入邮箱'), builtinRules.email('请输入有效的邮箱地址')]
}
],
onSubmit: async (formData) => {
console.log('表单数据:', formData)
}
}
const handleSubmit = (formData) => {
console.log('提交数据:', formData)
}
const handleFieldChange = (prop, value, formData) => {
console.log('字段变化:', prop, value)
}
</script>
<template>
<FormBuilder />
</template>
<script setup>
import { FormBuilder } from 'element-plus-dynamic-form'
</script>
{
prop: 'username',
label: '用户名',
type: 'input',
placeholder: '请输入用户名',
maxlength: 20,
minlength: 3,
showWordLimit: true,
clearable: true
}
{
prop: 'description',
label: '描述',
type: 'textarea',
placeholder: '请输入描述',
rows: 4,
maxlength: 200,
showWordLimit: true,
resize: 'vertical'
}
{
prop: 'category',
label: '分类',
type: 'select',
placeholder: '请选择分类',
options: [
{ label: '选项1', value: 'option1' },
{ label: '选项2', value: 'option2' }
],
clearable: true,
filterable: true,
multiple: false
}
{
prop: 'gender',
label: '性别',
type: 'radio',
options: [
{ label: '男', value: 'male' },
{ label: '女', value: 'female' }
],
border: true
}
{
prop: 'hobbies',
label: '兴趣爱好',
type: 'checkbox',
options: [
{ label: '读书', value: 'reading' },
{ label: '运动', value: 'sports' }
],
min: 1,
max: 3
}
{
prop: 'birthday',
label: '生日',
type: 'date',
placeholder: '请选择生日',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
clearable: true
}
{
prop: 'age',
label: '年龄',
type: 'number',
placeholder: '请输入年龄',
min: 0,
max: 120,
step: 1,
controls: true
}
{
prop: 'enabled',
label: '启用',
type: 'switch',
activeValue: true,
inactiveValue: false,
activeText: '启用',
inactiveText: '禁用'
}
{
prop: 'score',
label: '评分',
type: 'slider',
min: 0,
max: 100,
step: 1,
showInput: true,
showTooltip: true
}
{
prop: 'avatar',
label: '头像',
type: 'upload',
action: '/api/upload',
accept: 'image/*',
maxSize: 5,
maxCount: 1,
drag: true
}
import { builtinRules } from 'element-plus-dynamic-form'
// 必填
builtinRules.required('此字段是必填项')
// 邮箱
builtinRules.email('请输入有效的邮箱地址')
// 手机号
builtinRules.phone('请输入有效的手机号')
// URL
builtinRules.url('请输入有效的URL')
// 数字
builtinRules.number('请输入有效的数字')
// 整数
builtinRules.integer('请输入整数')
// 长度限制
builtinRules.minLength(3, '最少3个字符')
builtinRules.maxLength(20, '最多20个字符')
// 数值范围
builtinRules.min(0, '不能小于0')
builtinRules.max(100, '不能大于100')
// 自定义验证
builtinRules.custom((value, formData) => {
// 返回 true 表示验证通过
// 返回 false 或字符串表示验证失败
return value.length >= 6
}, '密码至少6位')
{
prop: 'password',
label: '密码',
type: 'input',
rules: [
{
required: true,
message: '请输入密码'
},
{
validator: (rule, value, formData) => {
if (value.length < 6) {
return new Error('密码至少6位')
}
return true
}
}
]
}
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| config | 表单配置 | DynamicFormConfig | - |
| showSubmitButton | 是否显示提交按钮 | boolean | true |
| showResetButton | 是否显示重置按钮 | boolean | true |
| submitButtonText | 提交按钮文本 | string | '提交' |
| resetButtonText | 重置按钮文本 | string | '重置' |
| modelValue | 表单数据 | Record<string, any> | {} |
| 事件名 | 说明 | 参数 |
|---|---|---|
| submit | 表单提交 | (formData: Record<string, any>) |
| reset | 表单重置 | () |
| field-change | 字段值变化 | (prop: string, value: any, formData: Record<string, any>) |
| update:modelValue | 表单数据更新 | (formData: Record<string, any>) |
| 方法名 | 说明 | 参数 | 返回值 |
|---|---|---|---|
| getFormData | 获取表单数据 | - | Record<string, any> |
| setFormData | 设置表单数据 | (data: Record<string, any>) | void |
| validate | 验证表单 | - | Promise |
| validateField | 验证指定字段 | (prop: string) | Promise |
| resetForm | 重置表单 | - | void |
| clearValidate | 清除验证 | (props?: string[]) | void |
| submit | 提交表单 | - | Promise |
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| prop | 字段唯一标识 | string | - |
| label | 字段标签 | string | - |
| type | 字段类型 | FieldType | - |
| value | 字段值 | any | - |
| required | 是否必填 | boolean | false |
| disabled | 是否禁用 | boolean | false |
| readonly | 是否只读 | boolean | false |
| placeholder | 占位符 | string | - |
| help | 帮助文本 | string | - |
| width | 字段宽度 | string | number | - |
| visible | 是否显示 | boolean | true |
| className | 自定义样式类 | string | - |
| rules | 验证规则 | FormRules[string] | - |
| dependencies | 字段依赖 | string[] | - |
{
prop: 'country',
label: '国家',
type: 'select',
options: [
{ label: '中国', value: 'china' },
{ label: '美国', value: 'usa' }
]
},
{
prop: 'city',
label: '城市',
type: 'select',
dependencies: ['country'], // 依赖country字段
options: [] // 根据country动态设置
}
{
prop: 'custom',
label: '自定义字段',
type: 'custom',
component: MyCustomComponent,
componentProps: {
// 传递给自定义组件的属性
}
}
表单构建器提供了可视化的表单设计界面:
# 安装依赖
npm install
# 开发模式
npm run dev
# 构建
npm run build
# 类型检查
npm run type-check
# 代码检查
npm run lint
MIT
欢迎提交 Issue 和 Pull Request!
FAQs
基于 Element Plus 的动态表单组件库
We found that element-plus-dynamic-form-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.