I'm using Vue.js, and I want to hide the elements until after the call to the Vue constructor because otherwise, a bunch of curly braces get flashed to the user. I have the following:
HTML:
<div class="main hide-me" id="my-vue-element">
<!-- stuff -->
</div>
CSS:
.hide-me {
display: none !important;
}
JavaScript:
var myVueElement = document.getElementById("my-vue-element");
if (myVueElement) {
var myApp = new Vue({
el: myVueElement
, data: {
/* stuff */
}
, methods: {
/* stuff */
}
});
console.log(myVueElement);
console.log(myVueElement.classList);
myVueElement.classList.remove("hide-me");
console.log(myVueElement.classList);
console.log(myVueElement.getAttribute("class"));
The console output is:
DOMTokenList [ "main", "hide-me" ]
DOMTokenList [ "main" ]
main
However, the element does not appear, and using the DOM inspectors in Firefox and in Chrome shows the hide-me
class is still there. I've tried to reproduce this using a simplified example but am unable to do so. I do have jQuery in this same project, and I found that using $("#my-vue-element").removeClass("hide-me");
(or even adding it after the above code) causes the class to be removed from the DOM. Any ideas? Thanks!