



























vue2 hooks useInnerHeight.vue 解决Table高度实时更新
iview Table组件 有一个height的属性,为了实现浏览器改变,需要高度实时变化
/src/hooks/useInnerHeight.vue
<template>
<span style="display: hidden;"></span>
</template>
<script>
export default {
components: {},
props: {
value: Number
},
data () {
return {
innerHeight: window.innerHeight,
}
},
watch: {},
computed: {
},
methods: {
resizeHeight() {
this.$emit('input', window.innerHeight)
},
},
created () { },
activated () { },
mounted () {
window.addEventListener("resize", this.resizeHeight);
},
beforeDestroy () {
window.removeEventListener("resize", this.resizeHeight);
}
}
</script>
<style lang="less" scoped>
</style>
<template>
<div id="app" style="width: 100%; height: 100%;">
<useInnerHeight v-model="innerHeight"/>
</div>
</template>
<script>
import useInnerHeight from '@/hooks/useInnerHeight'
export default {
name: 'App',
components: { useInnerHeight },
data () {
return {
innerHeight: window.innerHeight,
}
},
computed: {
},
created () {
Vue.prototype.$app = this
},
methods: {
},
mounted () {
},
destroyed () {
}
}
</script>
<style scoped lang="less">
</style>
<template>
<div class="container-table mt10">
<Table
:height="tableHeight"
>
</Table>
</div>
</template>
<script>
export default {
components: {},
props: {},
data () {
return {
}
},
watch: {},
computed: {
tableHeight() {
return this.$app.innerHeight - 180 - 40;
},
},
methods: {
},
created () { },
activated () { },
mounted () {
},
beforeDestroy () {
}
}
</script>
<style lang="less" scoped>
</style>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。