vue中动态使用vh calc设置高度

文章讲述了在Vue.js应用中如何动态设置<div>元素的高度。通过数据绑定和计算属性,结合CSS的calc函数,调整元素高度以适应页面布局,同时考虑了logo区域的高度。此方法用于实现响应式和自适应的界面设计。

动态设置高度
在这里插入图片描述

  <div class="user_menu_box" :style="menuHeight">
          <!-- 用户信息 -->
          <div class="user_info" :class="{ 'menu-collase': isCollapse }">
            <img
              src="@/assets/login_images/bg.jpg"
              alt="暂无图片"
              class="user_img"
            />

在这里插入图片描述

 data() {
    return {
      bigBackground: ['/allProject', '/approvalList', '/agentProjectList','/workBench'],
      path: '',
      menuHeight: {},
      activeMenuUrl: '',
      searchInput: '',
      menuIndex: '0',
      comeUrl: '', //判断子页面从哪个列表来
    }
  },

在这里插入图片描述

 // 设置卡片列表高度
    setMenuHeight() {
      this.$nextTick(() => {
        const layoutHeight = this.$refs.layoutHeight.offsetHeight
        const logoHeight = this.$refs.logoHeight.offsetHeight
        let logoHeights=logoHeight+'px'
        this.menuHeight = {height: 'calc(100vh - '+logoHeights+')'}
      
      })
    },
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值