How to dynamically add css in vue
Jul 26, 2021 am 11:55 AMHow vue dynamically adds css is: 1. Bind dynamic styles to elements with the syntax "<div class="name" :class="css style name">"; 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">
2. Add multiple styles
<div id="addInvite" class="addInvite" :class="[addInviteHeight1, addInviteHeight2]">
Second Step: Define data objects in data
data: { addInviteHeight1: '', // 弹框的高度 addInviteHeight2: '', // 弹框的高度 lightBlue: 'lightBlue', // lightBlue是css中定义的样式名 }
Step three: Write styles in css
.addInviteHeight1 { height: 52.5rem; } .addInviteHeight1 { height: 48rem; } .lightBlue { background-color: #6e9dd3; }
[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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is Vuex and how do I use it for state management in Vue applications?

How to configure the watch of the component in Vue export default

What are the key features of Vue.js (Component-Based Architecture, Virtual DOM, Reactive Data Binding)?

How do I implement advanced routing techniques with Vue Router (dynamic routes, nested routes, route guards)?

How do I create and use custom plugins in Vue.js?

How do I configure Vue CLI to use different build targets (development, production)?

What is Vue Router and how do I use it for single-page application (SPA) navigation?

How to configure the lifecycle hooks of the component in Vue
