forked from lecion/vue-perfect-scrollbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.vue
55 lines (54 loc) · 1.32 KB
/
index.vue
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
55
<template>
<section ref="container"
@ps-scroll-y="scrollHanle"
@ps-scroll-x="scrollHanle"
@ps-scroll-up="scrollHanle"
@ps-scroll-down="scrollHanle"
@ps-scroll-left="scrollHanle"
@ps-scroll-right="scrollHanle"
@ps-y-reach-start="scrollHanle"
@ps-y-reach-end="scrollHanle"
@ps-x-reach-start="scrollHanle"
@ps-x-reach-end="scrollHanle">
<slot></slot>
</section>
</template>
<style lang="scss">
@import '~perfect-scrollbar/src/css/main.scss';
</style>
<script>
import scrollBar from 'perfect-scrollbar'
// import scrollBar from 'psScrollbar'
export default {
props: {
settings: {
default: undefined
}
},
methods: {
scrollHanle(evt) {
this.$emit(evt.type, evt)
},update(){
let container = this.$refs.container;
scrollBar.update(container)
}
},
mounted() {
let container = this.$refs.container
this.width = container.offsetWidth
this.height = container.offsetHeight
scrollBar.initialize(container, this.settings)
},
beforeDestroy() {
scrollBar.destroy(this.$refs.container)
},
updated() {
let container = this.$refs.container,
width = container.offsetWidth,
height = container.offsetHeight
if (width != this.width || height != this.width) {
scrollBar.update(container)
}
}
}
</script>