Skip to content

nextTick doesn't always ensure the element is already in the DOM #289

@JosephSilber

Description

@JosephSilber

Some directives can only work on elements that are already in the DOM, such as autofocus:

Vue.directive('autofocus', {
    bind() {
        Vue.nextTick(() => this.el.focus())
    }
});

However, the page component is compiled right away but it's only inserted into the DOM when it's mounted after the data and activate hooks are done. This results in nextTick running before the element is in the DOM, resulting in the element never getting focus.

Since nextTick obviously doesn't ensure that the element is in the DOM, what can be used instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions