移动端footer置底

先获取屏幕高度,然后减去头部和底部,给中间content加一个最小高度

<template>
    <div id="app">
        <Header></Header>
        <div id="v-content" :style="{minHeight: height+'px'}"><router-view /></div>
        <Footer></Footer>
    </div>
</template>
 
<script>
export default {
  name: 'App',
  data() {
     return {
       height: 0
     }
  },
  mounted(){
    //动态设置内容高度 让footer始终居底   header+footer的高度是100
    this.height = document.documentElement.clientHeight - 100;  
  //监听浏览器窗口变化 
    window.onresize = ()=> {this.height = document.documentElement.clientHeight -100}
  }
}
</script>

评论

暂无评论