OverlayScrollbars icon indicating copy to clipboard operation
OverlayScrollbars copied to clipboard

Using Vue OverlayScrollbarsComponent.osInstance() got null

Open HaceraI opened this issue 4 years ago • 3 comments

This is the first time that I've applied OverlayScrollbars to my Vue project, and now I've got a little problem

The version I use is: overlayscrollbars: ‘1.13.1’ overlayscrollbars-vue: '0.2.2'

Before using it, I looked up the official example: https://github.com/KingSora/OverlayScrollbars/blob/master/packages/overlayscrollbars-vue/example/src/App.vue

I want to change the scroll of overlay scrollbars. First, I call osinstance () to get the instance, but when I use this method, it returns a null Can you take a look for me? image image When osinstance () returns null image image

If there is anything wrong with me, I hope you can point it out. Thank you very much for your help

Tips: English is not my native language; please excuse typing errors.

HaceraI avatar Dec 30 '20 11:12 HaceraI

Good day @HaceraI!

Please create a small example of your problem in CodeSandbox or StackBlitz. I can't spot anything wrong in your provided screenshots.

KingSora avatar Dec 30 '20 19:12 KingSora

@KingSora This is the CodeSandbox link: https://codesandbox.io/s/nifty-framework-4ubb8?file=/src/App.vue:2248-2293 Of course, I also created the corresponding warehouse in GitHub: https://github.com/HaceraI/OverlayScrollbars-vue-example

I seem to have found the reason If I don't add judgment, the first time. scroll() will report an error, and then the entire. osInstance() will get null

At present, I add if judgment to the place where. Scroll() is used. If you want to see the abnormal effect, you can try to remove lines 90 and 92 image

Thank you very much for helping me

HaceraI avatar Dec 31 '20 02:12 HaceraI

Thanks!

I got the issue, but I'm not sure why it happens yet. You see, the osInstance is available after the mounted lifecycle method, but for some reason I don't know yet the onContentSizeChanged callback is called before that. Thats also why your if condition is fixing it.. I'll look deeper into it as soon as I have a bit more time. You can check this behavior yourself by placing a console.log in the mounted method like I did here: https://codesandbox.io/s/epic-galois-2glbm?file=/src/App.vue

KingSora avatar Dec 31 '20 12:12 KingSora

overlayscrollbars v2 released today and with it a new version of overlayscrollbars-vue where this issue should be fixed

KingSora avatar Nov 12 '22 12:11 KingSora