Home > Web Front-end > Vue.js > body text

How to dynamically set element height in vue.js

王林
Release: 2021-10-09 17:42:21
Original
5404 people have browsed it

vue.js method to dynamically set element height: [<div :style="{width: divWidth, height: divHeight}"></div>data() {//Storing data} 】.

How to dynamically set element height in vue.js

The operating environment of this article: windows10 system, vue.js 2.9, thinkpad t480 computer.

Without further ado, let’s go directly to the code:

vue code:

<div :style="{width: divWidth, height: divHeight}"></div>
Copy after login

data data:

data() {
    //这里存放数据
    return {
        divHeight:0,
        divWidth:0
    }
},
Copy after login

created method assignment

created(){
    let divWidth = document.body.clientWidth+"px";
    let divHeight = document.body.clientHeight-130+"px";
    this.divWidth = divWidth
    this.divHeight = divHeight
},
Copy after login

Recommended learning: php training

The above is the detailed content of How to dynamically set element height in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template