mercs600 / vue2-perfect-scrollbar

Vue.js wrapper for perfect scrollbar
https://mercs600.github.io/vue2-perfect-scrollbar/
MIT License
275 stars 43 forks source link

How to listen to PS custom events #8

Closed hfalucas closed 5 years ago

hfalucas commented 5 years ago

In the docs says you can listen to Perfect Scrollbar custom events and it refers to the PS documentation where it shows:

container.addEventListener('ps-scroll-x, ...)

In my app I'm trying this but with no success:

<scroll-bar ref="scroll"> ... </scroll-bar>

// error: addEventListener is not a function
mounted () {
    this.$refs.scroll.addEventListenter('ps-scroll-x', () => {
        consolellog(...)
    })
}

// error: nothing happens
mounted () {
    this.$refs.scroll.$el.addEventListenter('ps-scroll-x', () => {
        console.log(...)
    })
}

I am obviously missing something. How can I listen to the PS events?

Thanks in advance.

mercs600 commented 5 years ago

@hfalucas you can use vuejs directive to listening events on: https://vuejs.org/v2/guide/events.html just add @ps-scroll-x to your scrollbar element

<scroll-bar ref="scroll" @ps-scroll-x="someMethodToHandle">

and then

methods: {
  someMethodToHandle() {
   console.log('scroll x')
  }
}

Let's see example here: https://codesandbox.io/s/00w2rk5k7v

hfalucas commented 5 years ago

I did try that before opening the issue but I guess "scoll" was not really a word -.-

Thank you @mercs600 for such quick answer and helpful examples.