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
<template>
<div :id="contentRef" class="c-content-scrollbar c-content-item" style="width: 100%;height: 100%;">
<slot></slot>
</div>
</template>
<script>
export default {
props: {
height: {
type: Number,
require: false,
default: function() {
return this.$route.path.startsWith('/display/') ? 100 : 240
}
}
},
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{
overflow-y: auto;
overflow-x: hidden;
}
.c-content-item:nth-child(2){
flex:1;
}
</style>