weixin_58412143 2022-03-03 10:34 采纳率: 92.1%
浏览 214
已结题

Vue 如何让高度自适应

img


现在是给了flex布局,外层盒子高度是自适应的,但是里面的内容没有


<div class="body-box" v-if="logshow&&hjshow" :style="'height:'+bgheight+'px;'">//父级盒子
            <!-- 第一行数据 -->
            <div class="content-box"  :style="'height:'+((screenHeight-147)/2)+'px;'">
                    //这里是三个小组件横向排列
            <!-- 第二行数据 -->
            <div class="bototm-box">
                    //这里也是三个小组件横向排列
——JS
var screenHeight= document.documentElement.clientHeight;
  var screenWidth=document.documentElement.clientWidth;
  var ratio = screenHeight / 1080;
         console.log(ratio);
  var bgheight=ratio*1080;
  console.log(bgheight);
watch: {
          screenHeight (val) {
            // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
            if (!this.timer) {
              // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
              this.screenHeight = val
              this.timer = true
              let that = this
              setTimeout(function () {
                // 打印screenWidth变化的值
                console.log(that.screenHeight)
                that.timer = false
              }, 400)
            }
          },
          screenWidth (val) {
            if (!this.timer) {
              this.screenWidth = val
              this.timer = true
              let that = this
              setTimeout(function () {
                console.log(that.screenWidth)
                that.timer = false
              }, 400)
            }
          }
        },
  • 写回答

1条回答 默认 最新

  • iloveozz 2022-03-03 15:54
    关注
    <div style="height:100%"></div>
    

    这样高度就随着父元素自适应啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月18日
  • 已采纳回答 3月10日
  • 创建了问题 3月3日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效