Skip to content

Online Examples ​

The following are FormCreate's feature demonstrations and reference cases to help developers quickly understand how to use and extend it in actual projects.

Simple Example ​

A simple form example showing how to use FormCreate to generate forms and handle submit events.

Usage Tutorial ​

Detailed usage tutorials help you understand FormCreate's features and usage more deeply.

Business Scenario Examples ​

FormCreate plays an important role in various business scenarios. The following are several common application scenarios:

Dynamic Form Generation ​

Suppose you have a form that needs to be dynamically generated based on user selection. Use FormCreate to achieve this:

Form Linkage Effects ​

Easily implement linkage between form items, such as dynamically showing or hiding other form items based on the value of a dropdown box.

Dynamic Component Loading ​

In complex scenarios, dynamically load different components based on business logic. FormCreate provides a flexible dynamic loading mechanism.

js
const dynamicComponent = () => import('./CustomComponent.vue');


const rule = ref([
    {
        component: dynamicComponent,
        field: 'custom_field',
        title: 'Custom Component'
    }
]);

Using Custom Components ​

In addition to built-in components, integrate custom Vue components into FormCreate to easily achieve complex business requirements.

js
import MyCustomComponent from './MyCustomComponent.vue';
import formCreate from '@form-create/element-ui';


formCreate.component('MyCustomComponent', MyCustomComponent);


const rule = ref([
    {
        type: 'MyCustomComponent',
        field: 'custom_field',
        title: 'Custom Component'
    }
]);

Loading Initial Data ​

In some scenarios, load initial data from an API and populate it into the form. Make API requests after form loading through the mounted hook and bind the obtained data to the form.

js
export default {
    data() {
        return {
            formData: {},
            rule: [
                { type: 'input', field: 'username', title: 'Username' },
                { type: 'input', field: 'email', title: 'Email' }
            ],
            option: {
                onSubmit: (formData) => {
                    console.log('Submit form data:', formData);
                }
            }
        };
    },
    mounted() {
        axios.get('/api/user')
            .then(response => {
                this.formData = response.data;
            });
    }
};

Form Data Submission ​

FormCreate provides convenient form submission methods. Send data to the server when submitting the form.

js
const options = ref({
    submitBtn: true,
    resetBtn: true,
    onSubmit: function (formData) {
        axios.post('/api/submit', formData)
            .then(response => {
                console.log('Submit successful:', response.data);
            })
            .catch(error => {
                console.error('Submit failed:', error);
            });
    }
});
// or
api.submit((formData)=>{
    axios.post('/api/submit', formData)
        .then(response => {
            console.log('Submit successful:', response.data);
        })
        .catch(error => {
            console.error('Submit failed:', error);
        });
})

Custom Validation Rules ​

In addition to built-in validation rules, FormCreate lets you customize validation logic to meet complex business requirements.

js
const rule = ref([
    {
        type: 'input',
        field: 'username',
        title: 'Username',
        validate: [
            { required: true, message: 'Username cannot be empty' },
            {
                validator: async (rule, value) => {
                    const isExist = await axios.get(`/api/check-username?username=${value}`);
                    if (isExist.data) {
                        return Promise.reject('Username already registered');
                    } else {
                        return Promise.resolve();
                    }
                },
                trigger: 'blur'
            }
        ]
    },
    {
        type: 'input',
        field: 'password',
        title: 'Password',
        validate: [
            { required: true, message: 'Password cannot be empty' },
            {
                validator: (rule, value) => {
                    if (value.length < 6) {
                        return Promise.reject('Password length cannot be less than 6 characters');
                    } else {
                        return Promise.resolve();
                    }
                },
                trigger: 'blur'
            }
        ]
    }
]);

Component Examples ​

Advanced Components ​

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.