-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.vue
81 lines (72 loc) · 1.44 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<section class="ps-container" :is="$props.tagname" @mouseover.once="update" v-on="$listeners">
<slot></slot>
</section>
</template>
<style lang="scss">
@import "~perfect-scrollbar/css/perfect-scrollbar.css";
.ps-container {
position: relative;
}
</style>
<script>
import PerfectScrollbar from "perfect-scrollbar";
export default {
name: "vue-perfect-scrollbar",
props: {
settings: {
default: undefined
},
tagname: {
type: String,
default: "section"
}
},
data() {
return {
ps: null
};
},
methods: {
update() {
if (this.ps) {
this.ps.update();
}
},
__init() {
if (!this.ps) {
this.ps = new PerfectScrollbar(this.$el, this.settings);
}
},
__uninit() {
if (this.ps) {
this.ps.destroy();
this.ps = null;
}
}
},
watch: {
$route() {
this.update();
}
},
mounted() {
// for support ssr
if (!this.$isServer) {
this.__init();
}
},
updated() {
this.$nextTick(this.update);
},
activated() {
this.__init();
},
deactivated() {
this.__uninit();
},
beforeDestroy() {
this.__uninit();
}
};
</script>