I am using VueScroll as a container for a carousel. Unfortunately I noticed that when a user has their mouse on the VueScroll element and wheel-scrolls the elements inside the VueScroll to zoom in/out. I am wanting to get the element and add a listener to handle the wheel scroll event.
To get the element I tried the following:
created(){
if(process.client){
if(document.getElementById('vueScroller')){
console.log('vueScroller created');
} else {
console.log('fail...')
}
}
},
And I noticed that on the initial load I get "fail..." but if I change something in the code and the app hotreloads I get "vueScroller created", so I figure I am close but not understanding where I am going wrong and/or why it acts differently depending on what triggers the page to load.
I am using VueScroll as a container for a carousel. Unfortunately I noticed that when a user has their mouse on the VueScroll element and wheel-scrolls the elements inside the VueScroll to zoom in/out. I am wanting to get the element and add a listener to handle the wheel scroll event.
To get the element I tried the following:
created(){
if(process.client){
if(document.getElementById('vueScroller')){
console.log('vueScroller created');
} else {
console.log('fail...')
}
}
},
And I noticed that on the initial load I get "fail..." but if I change something in the code and the app hotreloads I get "vueScroller created", so I figure I am close but not understanding where I am going wrong and/or why it acts differently depending on what triggers the page to load.
Share Improve this question edited Nov 16, 2019 at 23:22 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Nov 5, 2019 at 16:48 av0000av0000 1,9676 gold badges34 silver badges55 bronze badges 1- 2 Use a ref instead of a DOM lookup – Chase DeAnda Commented Nov 5, 2019 at 23:05
1 Answer
Reset to default 3If you use created()
the template has not yet been rendered. Using beforeMount()
or mounted()
should fix your problem.
Have a look at the life cycle diagram for reference: https://v2.vuejs/v2/guide/instance.html#Lifecycle-Diagram
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745304372a4621621.html
评论列表(0条)