需求:当页面高度不足一屏时需要footer固定显示在页面底部,而页面内容超过一屏时需要footer紧跟在页面内容的最后。

思路:通过获取 网页可见区域高度:document.body.clientHeight;设置内容区域的最小高度,从而曲线救国使footer置底。

代码:

<template>
    <div >
        <Header></Header>
        <div ><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>

 

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2021-06-11
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-03-02
  • 2021-09-28
  • 2021-12-29
  • 2021-06-20
相关资源
相似解决方案