Geeks_Z の Blog Geeks_Z の Blog
首页
  • 学习笔记

    • 《HTML》
    • 《CSS》
    • 《JavaWeb》
    • 《Vue》
  • 后端文章

    • Linux
    • Maven
    • 汇编语言
    • 软件工程
    • 计算机网络概述
    • Conda
    • Pip
    • Shell
    • SSH
    • Mac快捷键
    • Zotero
  • 学习笔记

    • 《数据结构与算法》
    • 《算法设计与分析》
    • 《Spring》
    • 《SpringMVC》
    • 《SpringBoot》
    • 《SpringCloud》
    • 《Nginx》
  • 深度学习文章
  • 学习笔记

    • 《PyTorch》
    • 《ReinforementLearning》
    • 《MetaLearning》
  • 学习笔记

    • 《高等数学》
    • 《线性代数》
    • 《概率论与数理统计》
  • 增量学习
  • 哈希学习
GitHub (opens new window)

Geeks_Z

AI小学生
首页
  • 学习笔记

    • 《HTML》
    • 《CSS》
    • 《JavaWeb》
    • 《Vue》
  • 后端文章

    • Linux
    • Maven
    • 汇编语言
    • 软件工程
    • 计算机网络概述
    • Conda
    • Pip
    • Shell
    • SSH
    • Mac快捷键
    • Zotero
  • 学习笔记

    • 《数据结构与算法》
    • 《算法设计与分析》
    • 《Spring》
    • 《SpringMVC》
    • 《SpringBoot》
    • 《SpringCloud》
    • 《Nginx》
  • 深度学习文章
  • 学习笔记

    • 《PyTorch》
    • 《ReinforementLearning》
    • 《MetaLearning》
  • 学习笔记

    • 《高等数学》
    • 《线性代数》
    • 《概率论与数理统计》
  • 增量学习
  • 哈希学习
GitHub (opens new window)
  • Linux

  • Java

  • 微服务笔记

  • MySQL

  • Nginx

  • HTML

  • CSS

  • JavaWeb

  • Vue

    • Start
    • Node和NPM
    • 快速入门
    • Vue实例
    • 组件化
    • 模块化
    • webpack
    • vue-cli
    • Promies
    • Vuex
    • Axios
    • vue-router
    • ref $refs(元素、组件引用 )
    • 生命周期
    • Mix(混入)配置项
    • 安装插件 use()
    • 功能样式
      • Vue 动态设置元素高度
        • Vue 文件如下
        • 说明
        • window 下的各种宽高度
    • 项目开发配置
    • 样式绑定
    • 事件
  • Git

  • 开发规范

  • SpringCloud微服务权限系统

  • bug

  • Software

  • ProgramNotes
  • Vue
Geeks_Z
2022-10-28
目录

功能样式

功能样式

Vue 动态设置元素高度

Vue 文件如下

<template>
  <div :style="autoHeight"></div>
</template>
<script>
  let windowHeight = parseInt(window.innerHeight)
  export default {
    data() {
      return {
        windowHeight: windowHeight,
        autoHeight: {
          height: ''
        },
      }
    },
    methods: {
      getHeight() {
        this.autoHeight.height = (windowHeight - 110) + 'px';
      },
    },
    created() {
        window.addEventListener('resize', this.getHeight)
        this.getHeight()
      },
      destroyed() {
        window.removeEventListener('resize', this.getHeight)
      }
  }
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

说明

  • 给div动态绑定 style 样式, 如autoHeight
<template><div :style="autoHeight"></div></template>
1
  • 获取浏览器高度后,经过计算后赋值
  let windowHeight = parseInt(window.innerHeight)
  export default {
    data() {
      return {
        windowHeight: windowHeight,
        autoHeight: {
          height: ''
        },
      }
    },
   methods: {
      getHeight() {
        this.autoHeight.height = (windowHeight - 110) + 'px';
      },
    },
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • created生命周期中,监听浏览器的变化
 created() {
        window.addEventListener('resize', this.getHeight)
        this.getHeight()
      },
 destroyed() {
        window.removeEventListener('resize', this.getHeight)
      }
1
2
3
4
5
6
7

window 下的各种宽高度

  • window.innerWidth 文档显示区(body)的宽度
  • window.innerHeight 文档显示区(body)的高度
  • window.outrWidth 窗口的宽度(body+任务栏)
  • window.outerHeight 窗口的高度(body+任务栏)
  • window.pageYOffset 文档左上角到文档显示区左上角的距离
  • screen.width 分辨率的宽度
  • screen.height 分辨率的高度
  • screen.availWidth 去掉任务栏剩余分辨率宽度
  • screen.availHeight 去掉任务栏剩余分辨率高度
上次更新: 2025/02/26, 08:57:57
安装插件 use()
项目开发配置

← 安装插件 use() 项目开发配置→

最近更新
01
RAIL
02-26
02
IOCTF
02-25
03
DGM
02-25
更多文章>
Theme by Vdoing | Copyright © 2022-2025 Geeks_Z | MIT License
京公网安备 11010802040735号 | 京ICP备2022029989号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式