vue2-scrollbar icon indicating copy to clipboard operation
vue2-scrollbar copied to clipboard

how to show the bar when I initialize it

Open husilang opened this issue 7 years ago • 6 comments

Hi In you demo, the scrollbar is always showing. But in my project, The scrollbar only display when I scrolling, I want it to be displayed when the component was initialized for the first time. What should I do? Thank you!

husilang avatar Nov 24 '17 10:11 husilang

Same issue here

hotrush avatar Dec 28 '17 14:12 hotrush

If you're loading your content of the scroll container with an ajax call, you'll need to have the scroll component wait for the response. Otherwise, it initializes with a zero height container, which makes the scrollbar itself hide.

zaclem01 avatar Feb 02 '18 18:02 zaclem01

@zaclem01 maybe any resize/re-render event on data changing? Otherwise it is some useles, because vue js is a modern framework for app with dynamic data, and most of this data can be loaded via ajax)

hotrush avatar Feb 04 '18 17:02 hotrush

I added a reference to the vue2-scrollbar component, then after the async data has been fetched, I call the calculateSize() method from the scrollbar reference; works like a charm.

<vue-scroll-bar ref="scrollbar"> ...your content... </vue-scroll-bar> this.$refs.scrollbar.calculateSize();

Hope it helps

raulhuelamo avatar Feb 05 '18 16:02 raulhuelamo

You can simply add

    updated ()
    {
      this.calculateSize()
    },

after the mounted() method in the vue-scrollbar source

tmcdos avatar Mar 25 '18 18:03 tmcdos

My solution

export default {
    components: {
        'vue-scrollbar': require('vue2-scrollbar')
    },
    data() {
        return {
            onceCalculateSizeScroll: true
        };
    },
    updated() {
        if (this.onceCalculateSizeScroll) {
            this.$refs.scrollbar.calculateSize();
            this.onceCalculateSizeScroll = false;
        }
    },
}

login2030 avatar Dec 20 '18 21:12 login2030