A
A
Alexander Ivanov2019-09-03 11:24:53
Vue.js
Alexander Ivanov, 2019-09-03 11:24:53

Can I track the change in $refs via updated in vue?

I use nuxt because need ssr

updated(){
    console.log(this.$refs['stickyHeader'].classList)
  },
  async mounted() { // липкое меню
    await this.$nextTick(function() {
      window.addEventListener("scroll", function(){
        const navbar = document.getElementById("stickyHeader")
        const nav_classes = navbar.classList
        if(document.documentElement.scrollTop >= 150) {
          if (nav_classes.contains("shrink") === false) {
            nav_classes.toggle("shrink");
          }
        }
        else {
          if (nav_classes.contains("shrink") === true) {
            nav_classes.toggle("shrink");
          }
        }
      })
    })
    this.$nextTick().then(function () {
      console.log(document.getElementById("stickyHeader").classList)
    })
  },

How do I get this.$refs['stickyHeader'].classList in via updated and is it possible?

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