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
<template>
<el-scrollbar :id="contentRef" class="c-content-scrollbar" style="width: 100%;">
<slot></slot>
</el-scrollbar>
</template>
<script>
export default {
props: {
height: {
type: Number,
require: false,
default: 250
}
},
data() {
return {
clientHeight: '',
contentRef: 'contentRef' + Math.floor(Math.random() * 100),
}
},
mounted() {
this.clientHeight = `${document.documentElement.clientHeight}`
this.changeFixed()
this.handleResizeBind = this.handleResize.bind(this, this.contentRef, this.height)
window.addEventListener('resize', this.handleResizeBind)
},
methods: {
changeFixed() {
let content = document.getElementById(this.contentRef)
if (content) {
content.style.height = this.clientHeight - this.height + 'px'
}
},
handleResize: (contentRef, height) => {
let content = document.getElementById(contentRef)
if(!content){
//切换顶部tab,会隐藏元素,所以有可能找不到
return
}
let clientHeight = `${document.documentElement.clientHeight}`
content.style.height = clientHeight - height + 'px'
}
},
destroyed: function () {
window.removeEventListener('resize', this.handleResizeBind)
}
}
</script>
<style>
.c-content-scrollbar .el-scrollbar__wrap{
overflow-y: scroll;
overflow-x: auto;
}
</style>