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 🙏

© 2024 – Pkg Stats / Ryan Hefner

elementplus_dy_form

v1.0.2

Published

Dynamic forms for Elementplus and Vue3

Downloads

7

Readme

dy_form

dy_form is a Dynamic forms for Elementplus and Vue3

Supports deep binding of values of complex data types

const form = ref<UserForm>({
    name: '',
    organization: '',
    date1: '',
    date2: '',
    delivery: false,
    type: [],
    resource: '',
    desc: '',
    personInfo:'',
    info:{
        address: "",
        job:""
    },
    infos:[
      {
          age:123
      }
    ]
});

只需要配置formKey

 // ...
		{
            type: ElInput,
            formConfig: {
                type: 'textarea'
            },
            formDataKey: 'info.address', 这样配置就行了
            formItemConfig: {
                label: '住址',
            }
        },
        {
          type: ElInput,
          formConfig: {
              type: 'textarea'
          },
        },
        formDataKey: 'infos.0.age', 这样配置就行了
          formItemConfig: {
            label: '年龄',
          }
        },
// ...

Usage

  • formConfig,formConfig will be passed to ElForm as its argument.

  • dyFormConfig

    • interface FormItemConfig<T = Props['modelValue']> {
        type?: any //component 
        formConfig?: Record<string, any>// As a property of the current type component
        formDataKey?: keyof T // Mapping key of the v-model
        formItemConfig?: Record<string, any>//As an attribute value for ElFormItem
        children?: FormItemConfig<T>[] | string
        slots?: Slots // Transferable slot
        next?: Next // Dynamically determine which form to return
        needFormItem?: boolean //If true, the ElFormItem is automatically added to the item
      }
      dyFormConfig:FormItemConfig[]
      interface Slots extends Record<string, () => any> {
        default: () => string | VNode
      }
      type Next = (formData: Props['modelValue']) => DyFormConfig[] | DyFormConfig
      eg:
          const dyFormConfig: FormItemConfig[] = [
              {
                  type: ElInput,
                  formItemConfig: {
                      label: '请输入姓名',
                      prop: "name"
                  },
                  formConfig: {
                      placeholder: '请输入姓名',
                  },
                  formDataKey: 'name'
              },
              {
                  type: ElSelect,
                  formItemConfig: {
                      label: '请选择组织',
                      prop:'organization'
                  },
                  formConfig: {
                      placeholder: '请选择您的组织'
                  },
                  formDataKey: 'organization',
                  children: [
                      {
                          type: ElOption,
                          formConfig: { label: '个人', value: 'person' },
          
                      },
                      {
                          type: ElOption,
                          formConfig: { label: '公司', value: 'company' }
                      },
                      {
                          type: ElOption,
                          formConfig: { label: '无', value: 'none' }
                      }
                  ],
      			  next(formData) {
                      const resource = formData.resource
                      const obj = {
                          'Sponsor': [
                              {
                                  type: ElInput,
                                  formDataKey: 'sponsorName',
                                  formItemConfig: {
                                      label: '请输入赞助商名称'
                                  },
                              }
                          ],
                          'Developer': [
                              {
                                  type: ElInput,
                                  formDataKey: 'developerName',
                                  formItemConfig: {
                                      label: '请输入开发商名称'
                                  },
                              }
                          ],
                      } as Record<string, FormItemConfig[]>
                      if (!resource) {
                          return []
                      } else {
                          return obj[resource]
                      }
                  },
              }      
      ]
<script setup lang="ts">
const dyForm = ref(null)
const { dyFormConfig }  = useDyFormConfig(dyForm)
const form = ref<UserForm>({
    name: '',
    organization: '',
    date1: '',
    date2: '',
    delivery: false,
    type: [],
    resource: '',
    desc: '',
    personInfo:''
});

const formConfig = reactive({
  labelWidth: '130px',
})

</script>

<template>
    <DyForm ref="dyForm" v-model="form" :dyFormConfig="dyFormConfig" :formConfig="formConfig" />
</template>

项目演示地址