How to get DOM element of current Vue component?

Kamil Kiełczewski picture Kamil Kiełczewski · Apr 11, 2016 · Viewed 26k times · Source

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...)

Answer

Kamil Kiełczewski picture Kamil Kiełczewski · Apr 11, 2016

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