Vue - where should I declare element variable to use in any lifecycle or method?

Viewed 79

I'm new to Vue and wondering where I would declare something like:

const qualityDropdown = document.getElementById("qualityDropdown");

in a single place so I can use it in any lifecycle and / or method in a component without having to re-declare it in every place. Part of the issue being that sometimes elements are created after an axios call and aren't immediately present.

Would this go in data(){return{}} or computed(){}?

1 Answers

You can define its ref as follows:

<select ref="myDropDown" id="qualityDropdown"></select>

And call it using

this.$refs.myDropDown
Related