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

How to dynamically add css in vue

醉折花枝作酒筹
Release: 2023-01-13 00:45:19
Original
12761 people have browsed it

How vue dynamically adds css is: 1. Bind dynamic styles to elements with the syntax "

"; 2. Define data objects in data; 3. Write styles in css.

The operating environment of this tutorial: windows7 system, vue2.9.6 version, Dell G3 computer.

Step 1: Bind dynamic styles to elements

1. Add a single style

<div class="addInvTitle" :class="lightBlue">
Copy after login

2. Add multiple styles

<div id="addInvite" class="addInvite" :class="[addInviteHeight1, addInviteHeight2]">
Copy after login

Second Step: Define data objects in data

data: {
    addInviteHeight1: &#39;&#39;, // 弹框的高度
    addInviteHeight2: &#39;&#39;, // 弹框的高度
    lightBlue: &#39;lightBlue&#39;,  // lightBlue是css中定义的样式名
}
Copy after login

Step three: Write styles in css

.addInviteHeight1 {
height: 52.5rem;
}
.addInviteHeight1 {
height: 48rem;
}
.lightBlue {
background-color: #6e9dd3;
}
Copy after login

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to dynamically add css in vue. 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