fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!--
 * @Descripttion:
 * @version: 1.0.0
 * @Author: Bridge
 * @Date: 2021-09-23 17:47:37
-->
 
<template>
  <div v-bind:class="{'my_scroll_container':true}" @scroll="getScroll"
       :style="`${scrollX==='true'||scrollX===true?'overflow-x:scroll;overflow-y:hidden':''};${scrollY==='true'||scrollY===true?'overflow-x:hidden;overflow-y:scroll':''};`">
    <slot></slot>
  </div>
</template>
<script>
export default {
  props: {
    scrollX: {
      type: [String, Boolean],
      value: false
    },
    scrollY: {
      type: [String, Boolean],
      value: false
    }
  },
  data () {
    return {
      scrollTop: 0
    }
  },
  methods: {
    // 滚动事件
    getScroll (e) {
      const wScrollY = e.target.scrollTop // 当前滚动条位置
      this.scrollTop = wScrollY
      const wInnerH = e.target.clientHeight // 设备窗口的高度(不会变)
      const bScrollH = e.target.scrollHeight // 元素总高度
      if (wScrollY + wInnerH >= bScrollH) {
        this.$emit('reachBottom')
      }
    }
  },
  created () {
    this.$el.scrollTop = this.scrollTop
    this.$emit('getScrollTop', { scrollTop: this.scrollTop })
  }
}
</script>
<style scoped>
.my_scroll_container {
  width: 100%;
  min-height: 250px;
}
</style>