element-plus-formkitelement-plus-formkit
  • 中文
  • English
GitHub
  • 中文
  • English
GitHub
  • Quick Start
  • Formkit API
  • Config API
  • Modules
  • Expose
  • Slot
  • Basic Demo
  • Extension Methods

registerModule

Register a custom module, type: Function. This method is used to register custom modules. For configuration options of custom modules, please refer to the Config API.

Parameters

  • type:Custom module type, type: String
  • config:Custom module configuration item, type: Function

Return value

  • void
Custom module

This is customModule

template
<formkit
    v-model="dataset"
    :config="[{
        type: 'customModule',
        label: 'Custom module',
        key: 'customModule',
    }]"
/>
script
<script setup lang="ts">
import formkit, { registerModule } from 'element-plus-formkit'
import { reactive, defineAsyncComponent } from 'vue'

const dataset = reactive({});

const customModule = defineAsyncComponent(() => import('/components/customModule.vue'))

registerModule("customModule", customModule)
</script>
customModule.vue
    <template>
        <h2>This is customModule</h2>
    </template>

    <script setup lang="ts">
        import { ref } from 'vue'
        const props = defineProps({
            value: {
                type: Object,
                default: () => ({})
            }
        })
    </script>

Tips

Of course, if you need to customize the visibility of a module, you can receive the visible property via props within the custom module and determine whether to display it based on this property. You can also register the custom module in main.ts.

setConfigure

Set the configuration item of a custom module, type: Function. This method is used to set the configuration item of a custom module.

Parameters

  • type:Custom module type, type: String, optional values: lang, upload.
    • lang:Language configuration item, type: ElementPlusLocale
    • upload:Upload configuration item, type: Function
  • config:Custom module configuration item, type: Function

Return value

  • void

Example of Uploading Configuration Items

import { setConfigure } from 'element-plus-formkit'
import type { UploadRequesterOptions } from 'element-plus-formkit/types/formkit-types'

setConfigure('upload', async (file: File, options: UploadRequesterOptions) => {
    const UploadFormData = new FormData()
    UploadFormData.append('file', file)
    const response = await useAxios().post("/default/oss/upload", UploadFormData, {
        headers: { 'Content-Type': 'multipart/form-data' },
        onUploadProgress: (progressEvent) => {
            const total = progressEvent.total || 1,
                loaded = progressEvent.loaded;
            options.onProgress?.({ total, loaded })
        }
    })
    return response
})

The above code enables your Formkit component to upload files.

Example of multilingual language configuration options

import { setConfigure } from 'element-plus-formkit'
import en from 'element-plus/es/locale/lang/en';

setConfigure('lang', en)

Tips

Formkit language packs depend on element-plus. For additional language settings, please refer to element-plus locale.

Upload Component

The Upload component is a module within Formkit designed for file uploads. It can also be exported and used independently.

Properties

NameTypeDescriptionDefault
limitNumberMaximum number of files to upload1
autoUploadBooleanEnable automatic uploadstrue
isCustomBooleanEnable custom uploadfalse
beforeUploadFunctionPre-upload callback function for preprocessing uploaded filesnull
afterUploadFunctionPost-upload callback function for postprocessing uploaded filesnull
acceptStringAccepted file types, e.g., ‘.jpg,.png’. To accept a unified file type category (e.g., images), use ‘image/*’-
sizeNumberUpload button size80

Tips

When using the upload component, if you've already configured upload settings (via the setConfigure method), you don't need to repeat the configuration. For the setConfigure key identical within your system, you only need to configure it once. Formkit will automatically handle the upload configuration.

template
<upload :size="100" accept="video/*" :limit="3" :after-upload="(response) => response.data" v-model="dataset.upload" />
script
<script setup lang="ts">
import formkit, { setConfigure, Upload, type UploadRequesterOptions } from 'element-plus-formkit'
import { reactive, defineAsyncComponent } from 'vue'

const dataset = reactive({});

// This section provides an example of upload configuration settings. If you have already configured upload settings in your project, you may skip this section.
setConfigure('upload', async (file: File, options: UploadRequesterOptions) => {
    const url = URL.createObjectURL(file)
    return new Promise((r, j) => {
        setTimeout(() => {
           r({
                code: 200,
                data: url || "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
           })
        }, 2000)
    })
})
</script>

Uploader Methods

Internal upload execution methods within the Uploader component, type: Function. You can export and use them individually. They include the following methods:

Method NameDescriptionTypeParametersReturn Value
constructorConstructorFunctionrequester?: UploadRequester Upload requesternull`
isValidFileTypeValidates file typeFunctionfile: File, accept: string (comma-separated file types, e.g., ‘video/,image/’)boolean
actionExecutes upload operationFunctionfile: File, a File objectvoid
destroyDestroys the upload componentFunctionvoidvoid
setProgressListenerSets the upload progress listenerFunction(progress: number) => voidvoid
setCompleteListenerSets the upload completion listenerFunction(response: any) => voidvoid
setErrorListenerSets the upload error listenerFunction(err: any) => voidvoid
import { Uploader } from 'element-plus-formkit'

const upload = new Uploader()

upload.action(File)

upload.setProgressListener((progress: number) => console.log('Upload progress:', progress))
upload.setCompleteListener(async (response: any) => {
    console.log('Upload complete:', response)
})
upload.setErrorListener((err) => {
    console.error('Upload error:', err)
    upload.destroy()
})

Address Component

The address component is a module within Formkit designed for selecting hierarchical regional addresses. It can also be exported for standalone use.

Tips

The core of the address module utilizes ELCascader, allowing parameters to be passed to ELCascader Attributes.

Properties

NameTypeDescriptionDefault
levelNumberHierarchical levels selectable by the address picker. Note: level starts at 0. Example: 0=>Province selection, 1=>Province/City selection1
cascaderPropsObjectWhen address uses ELCascader, cascaderProps contains parameters to pass to ELCascader cascaderprops{}
valueKeyStringKey name uniquely identifying the value. Required when binding an object type.id
labelKeyStringSpecifies the option label as a property value of the option object.name
template
<Address
    :level="1"
    v-model="dataset.address"
    :requester="(pid: number) => {
        return fetchOptions()
    }"
    :handler="(response: any) => response?.items || []",
    placeholder='Please select an address'
/>
script
<script setup lang="ts">
import formkit, { Address } from 'element-plus-formkit'
import { reactive, defineAsyncComponent } from 'vue'

const dataset = reactive({});

function fetchOptions() {
    return new Promise((r, j) => {
        setTimeout(() => {
           r({
                code: 200,
                items: [
                    { name: 'Option One', id: 1 },
                    { name: 'Option Two', id: 2 },
                    { name: 'Option Three', id: 3 }
                ]
           })
        }, 2000)
    })
}
Edit this page
Last Updated:: 2/4/26, 3:48 AM
Contributors: NicolasHome
Prev
Basic Demo