0

I have some issues in my Vue Code I want to create a ScrollToTop Button in Vue but I get this Error message in console:

Uncaught ReferenceError: $ is not defined

My Code :

export default {
  data() {
    return {
      isExample: false,
      }
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll);
  },
  methods: {
    handleScroll() {
      if (window.scrollY > 120) {
         this.isExample = true,
         $('.example-1').addClass("is-close"),
      } else if (window.scrollY < 120) {
         this.isExample = false,
         $('.example-1').removeClass("is-close")
      }
    }
  }
}
jhon-jhones
  • 455
  • 1
  • 13
  • 27

1 Answers1

0

Try to import jQuery in the component, or define $ globally in your application:

import $ from 'jquery'

Also, you can do this in js:

document.getElementsByClassName('example-1')
Majed Badawi
  • 27,616
  • 4
  • 25
  • 48
  • 1
    Please don't post answers on obviously off topic/bad questions! [See: **Should one advise on off topic questions?**](//meta.stackoverflow.com/q/276572) – double-beep Dec 26 '20 at 19:13
  • @double-beep OP is trying to use ``jquery`` in their ``vue`` application, so the problem is different than that marked as duplicate to – Majed Badawi Dec 26 '20 at 19:15