antdvuejs3antdvant-design-vue

How to write custom form component in Ant Design Vue 2x?


Ant Design Vue v1 provided a documented example for writing custom form components.

The same approach does not apply to version 2x.

How can a custom form component be implemented in AntDV 2x (vue 3) using useForm?


Solution

  • I believe I have figured this out. Previously your custom component needed to emit a change event:

    methods: {
        handleChange(value) {
            this.emit('change', value);
        },
    },
    

    Having looked through the source code I learned that you also need to emit an update:value event as well:

    methods: {
        handleChange(value) {
            this.emit('update:value', value);
            this.emit('change', value);
        },
    },