1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
< html lang = "en" >
< head >
  < meta charset = "UTF-8" >
  < title >Document</ title >
  < script type = "text/javascript" src = "https://unpkg.com/vue@2.2.6/dist/vue.js" ></ script >
  < style type = "text/css" >
  #box {
   width: 100%;
   height: 2000px;
  }
  </ style >
</ head >
< div id = "box" ></ div >
< body >
  <!-- vue监听滚动事件 -->
  < script type = "text/javascript" >
  var vm = new Vue({
    el:'#box',
   data() {
    return {
     scroll: ''
    }
   },
   methods: {
    menu() {
     this.scroll = document.body.scrollTop;
     console.log(this.scroll)
    }
   },
   mounted() {
    window.addEventListener('scroll', this.menu)
   },
  })
  </ script >
</ body >
</ html >
Logo

前往低代码交流专区

更多推荐