Reputation: 25
i'm using Nuxt.js and Vuetify, i'm trying to select an element with
mounted(){
console.log(this.$el.querySelector('#scroll-target'));
}
but i'm getting null in the console after the page compiling.
when i do this i can see my element :
mounted(){
setTimeout(function () {
console.log(this.$el.querySelector('#scroll-target'));
}.bind(this), 2000);
}
knowing that in the documentation it's mentioned that the $el is created before the mounted so can one explain to me why this happen ?
Upvotes: 0
Views: 6459
Reputation: 101
Looks like it should work to me, can we see the template? I also just tested it, and it works as expected in my vue enviroment.
The only situation where i seem to return null, is if the component is not rendered for whatever reason, v-if conditions etc.
Is it possible you can paste your template? Thanks
Upvotes: 2