vue页面div高度自适应

第一种方式:

<template>
  <div :style="conheight">
</template>
<script>
  export default{
    data(){
      conheight:{
                height:''
            }
    },
    methods:{
        getHeight(){
          this.conheight.height=window.innerHeight-170+'px';
       },
    created(){
        window.addEventListener('resize', this.getHeight);
        this.getHeight()
     }
  }
</script>

转载:https://www.cnblogs.com/Kyaya/p/10309148.html

第二种方式:

<template>
    <div class="bgColor" :style="'height:'+fullHeight+'px;'">
        <div class="login-wrap">
            <h1 class="login-title">评测管理员</h1>
            <div class="login-type-wrap">
                <router-link to="/login" class="logintype">登录</router-link>
                <router-link to="/registered" class="logintype">注册</router-link>
            </div>
            <router-view></router-view>
        </div>
    </div>
</template>
<script>
    export default{
        name:"Login",
        data () {
            return {
                fullHeight: document.documentElement.clientHeight
            }
        },
        watch: {
            fullHeight (val) {//监控浏览器高度变化
                if(!this.timer) {
                    this.fullHeight = val
                    this.timer = true
                    let that = this
                    setTimeout(function (){
                        that.timer = false
                    },400)
                }
                
            }
        },
        mounted () {
            this.get_bodyHeight()
        },
        methods :{
            get_bodyHeight () {//动态获取浏览器高度
                const that = this
                window.onresize = () => {
                    return (() => {
                        window.fullHeight = document.documentElement.clientHeight
                        that.fullHeight = window.fullHeight
                    })()
                }
            }
        }
    }
</script>

<style scoped>
@import '../../assets/style/auth/loginOrReg.css';
</style>

转载:https://blog.csdn.net/weixin_41628411/article/details/90475954

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。