In the Vue data
object there are the following variables defined:
data: function() {
return {
sails: document.querySelectorAll('.sail'),
sailsGroup: document.getElementsByClassName("sail"),
nameDisplay: document.querySelector('#name'),
lines: document.getElementById("lines"),
texts: document.getElementById("texts")
}
},
(...)
Then, there is this showData()
method, in the very same Vue object:
showData() {
console.log(sails);
console.log(sailsGroup);
console.log(nameDisplay);
console.log(lines);
console.log(texts);
},
(...)
When the method above is called from mounted()
hook, it gives: ReferenceError: nameDisplay is not defined at VueComponent.showData. The error appears in case of nameDisplay
and sails
variables, so the ones assigned with document.querySelector(All) methods. Calling them with this only gives empty array/value.
Why is it so? How to define variables to have them accessible?