Content.vue 1.33 KB
Newer Older
liuxin committed
1 2 3 4 5 6 7 8
<template>
	<el-scrollbar :id="contentRef" class="c-content-scrollbar" style="width: 100%;">
		<slot></slot>
	</el-scrollbar>
</template>

<script>
	export default {
潘际乾 committed
9 10 11 12
		props: {
			height: {
				type: Number,
				require: false,
潘际乾 committed
13
				default: 250
潘际乾 committed
14 15
			}
		},
liuxin committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
		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)
37 38 39 40
				if(!content){
					//切换顶部tab,会隐藏元素,所以有可能找不到
					return
				}
liuxin committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
				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>