VUE自适应FOOTER实现

该博客介绍项目使用Vue,代码在app.vue页。通过window.onresize监听窗口变化,还利用computed和watch监听vue - router的变化,同时提及了HTML、CSS和JS相关内容。

本项目使用Vue,代码位于app.vue页,通过window.onresize监听窗口变化,通过computed和watch监听vue-router的变化

HTML

          <Footer ref="footer" :style="{width:'100%',padding:'11px 50px'}"  :class="[(this.is_class_bottom) && this.$route.path != '/HomeDetail' ? 'footer_bottom':'footer_relative','layout-footer-center']">FOOTER</Footer>

CSS

.footer_bottom{
  position: fixed;
  bottom: 0;
}
.footer_relative{
  position: absolute;
}

JS

  mounted(){
    window.onresize = () => {
        return (() => {
          this.set_footer_position();
        })()
      }
  },
computed:{
    getName(){
      return this.$route.name;
    }
}
watch: {
    getName(){
        this.$nextTick(()=>{
          this.set_footer_position();
        })
    }
}
methods:{
    set_footer_position(){
        //表格未超出页面则footer的position:fixed
          //获取除footer以外所有元素高度和+HEADER+MARGINTOP
          let not_footer_height = this.$refs.content.$el.offsetHeight+this.$refs.content.$el.offsetTop; 
          //获取浏览器高度
          let client_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
          //获取Footer高度
          let footer_height = this.$refs.footer.$el.offsetHeight;    
          //判断n_f_h+footerHeight是否大于浏览器高度
          if(not_footer_height + footer_height > client_height){
            this.is_class_bottom = false;//超出则不放在底部
          }else{
            this.is_class_bottom = true;//未超出则放于底部
          }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值