search

Home  >  Q&A  >  body text

javascript - How to listen to mouse wheel events in vue.js.

It seems that writing @mousewheel has no effect, I hope God can give me some advice

伊谢尔伦伊谢尔伦2703 days ago1721

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-07-05 11:07:40

    Kuoyi, how did you write it specifically

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-05 11:07:40

    Okay, I made a mistake myself, because it was added to a component tag, it should be written @mousewheel.native~~

    reply
    0
  • 滿天的星座

    滿天的星座2017-07-05 11:07:40

    I am effective

    reply
    0
  • 大家讲道理

    大家讲道理2017-07-05 11:07:40

    You can write a command to monitor it yourself

    Vue.directive('scroll', {
      // 当绑定元素插入到 DOM 中
      inserted: function (el,binding) {
        var cb = binding.value
        el.addEventListener('mousewheel',function(e){
          var direction = e.deltaY>0?'down':'up'
          cb(direction)
        })
      }
    })
    
    new Vue({
      el:'#app',
      methods:{
        scrollFn:function(direction){
          console.log(direction)
        }
      }
    })

    jsbin

    reply
    0
  • Cancelreply