I am trying to access an external Element
in Vue by using the method getElementById()
:
new Vue({
el: "#vue",
data: {
helloElement: document.getElementById('hello')
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.2/vue.js"></script>
<div id="hello">
hello
</div>
<div id="vue">
{{helloElement}}
</div>
Although this code provides me with an empty Element
, it doesn't return a null
, indicating that the query was partially successful (something was found).
This is essentially a proof of concept for a larger issue I am dealing with: the ability to retrieve an external Element
(such as a container div
) from within a Vue component (which results in a null
, as per the documentation's explanation when the element is not located).
Is there a way, from inside a Vue object or component, to access an external Element
present in the HTML DOM?