R
R
Ruslan Absalyamov2019-02-19 17:58:14
Vue.js
Ruslan Absalyamov, 2019-02-19 17:58:14

Why does offsetTop always have the same value?

I am using tab method like here https://vuejs.org/v2/guide/components-dynamic-asyn...

<keep-alive>
  <component v-bind:is="currentTabComponent"></component>
</keep-alive>

But in my two tabs everything works fine autoscroll, but in one place it does not want to change. Let me tell you what I mean
watch: {
            scroll(value) {
                if (value) {//Если значение true то нужно сделать автоскролл
                    this.$nextTick(() => {
                        let el = document.getElementsByClassName("tab-body scrolling")[0];
                        el.scrollTop = this.$refs[this.itemName].offsetTop - this.$refs[this.itemName].scrollHeight;
//В итоге выходит в той вкладке которая проблемная, el.scrollTop = 0; 
// this.$refs[this.itemName].offsetTop = 729
//this.$refs[this.itemName].scrollHeight = 205
                    });
                }
            },
        },

And if you don't change the scrollTop even in the browser, then nothing changes. I don't understand why it is so. The tab-body scrolling class is the same for all of these tabs.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question