Ant Design Vue: Common Patterns and Solutions

  • The Popover component's hide animation may behave incorrectly on the first instance if its content is not wrapped in a block-level element.
  • Implementing hover effects can be achieved using CSS.
/* Target element is initially hidden */
.target-element {
    visibility: hidden;
}
/* On parent hover, show the target */
.parent-container:hover .target-element {
    visibility: visible;
}

  • To retrieve the selected node from a Tree component, you can use the onSelect event.
onSelectItem(selectedIds, event) {
    this.chosenItem = event.node.$vnode.data.props.dataRef;
}

  • In Vuex, commit is used for synchronous state mutations, while dispatch is used for asynchronous operations, often involving API calls.
// Synchronous mutation
this.$store.commit('updateSelection', selectedItem);
// Accessing the state
const currentSelection = this.$store.state.selection;

// Asynchronous action
this.$store.dispatch('fetchData', params);
// Accessing the getter
const retrievedData = this.$store.getters.fetchedData;

  • When passing objects or arrays from a parent to a child component, it's good practice to define them as props with a default value.
props: {
    itemsList: {
        type: Array,
        default: () => []
    }
},

  • A child component can watch for changes in a prop from its parent using the watch option, with deep and immediate options for comprehensive observation.
watch: {
    itemsList: {
        handler(newItems, oldItems) {
            this.localData = newItems ? [...newItems] : [];
        },
        deep: true,
        immediate: true
    }
},

  • Vue.nextTick() is essential for executing code after the DOM has been updated following a data change. It ensures you are working with the latest rendered DOM.

Vue's reactivity system does not update the DOM immediately after data changes. Instead, it batches updates for efficiency. Vue.nextTick() allows you to execute a callback function after the next DOM update cycle has been completed. This is particularly useful when you need to perform operations on the DOM that depend on the latest data, such as focusing an input or measuring an element's dimensions after it has been resized.

  • Note that Axios does not support sending a request body with a GET request. Parameters should be included in the URL's query string.
  • Vue filters can be used to format data directly in templates. For instance, you can create a filter to format dates.
{{ userMessage | formatDate }}
Here, `formatDate` is a filter function that takes the `userMessage` value as its first argument.

Formatting a date
<table-column key="registrationTime" title="Registration Date" data-index="registrationTime" width="20%" align="center">
    <template slot-scope="text">
      {{ text | formatDate }}
      {{ text | formatDate('YYYY-MM-DD HH:mm:ss') }}
    </template>
</table-column>

  • For MyBatis or similar ORMs, when using a generic insertList method, the entity class must either have exact one @Id annotation or none at all.
  • To prevent an event from bubbling up the DOM tree, you can use the .stop modifier in Vue.
<button @click.stop="processAction(item)">Process</button>
The `.stop` modifier calls `event.stopPropagation()`.
The `.prevent` modifier calls `event.preventDefault()`.

Preventing event bubbling in an Ant Design Popconfirm
<a-popconfirm>
  <a-icon type="edit" @click.stop/>
</a-popconfirm>

  • To execute code after the component's DOM has been fully rendered, you can use this.$nextTick() within the created lifecycle hook.
{
  created() {
    this.$nextTick(() => {
      // Code here will run after the DOM is updated
    });

    this.$nextTick().then(() => {
      // Promise-based syntax is also supported
    });
  }
}

  • To implement two-way data binding in a custom component, you can use the v-model directive, wich internally uses a value prop and an input event.
props: {
  // The model value
  modelValue: {
    type: String,
    default: ''
  }
},
this.$emit('update:modelValue', newValue);

  • Be aware that AOP (Aspect-Oriented Programming) mechanisms may not be able to intercept methods annotated on an interface.

Tags: Ant Design Vue Vue.js Vuex Vue Components Event Handling

Posted on Fri, 15 May 2026 09:14:29 +0000 by MentalMonkey