Kamil Kiełczewski
Kamil Kiełczewski

Reputation: 92687

How to get DOM element of current Vue component?

When I'm inside some method in vue commponent and want to use some dom manipulation (by jquery) I need to get DOM element coresponnding to my component (especially in case when I have many instances of my component on page - I need to 'work' separately on each of them - so I cannot detect DOM element using only jquery selector without tricks...)

Upvotes: 25

Views: 36696

Answers (1)

Kamil Kiełczewski
Kamil Kiełczewski

Reputation: 92687

Just by this (in any method in "methods"):

let domElement = this.$el;

:)

But remember this is valid as long as your component is not a Fragment Instance i.e. it has a single root HTML tag

Upvotes: 55

Related Questions