Home > Article > Web Front-end > A brief introduction to several styles used in Vue (with code)
This article brings you a brief introduction to several styles used in Vue (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Array
<h1 :class="['red', 'thin']">这是一个邪恶的H1</h1>
2. Use ternary expression in array
<h1 :class="['red', 'thin', isactive?'active':'']">这是一个邪恶的H1</h1>
3. Nested objects in array
<h1 :class="['red', 'thin', {'active': isactive}]">这是一个邪恶的H1</h1>
4. Use the object directly
<h1 :class="{red:true, italic:true, active:true, thin:true}">这是一个邪恶的H1</h1>
1. Write the style object directly on the element in the form of :style
<h1 :style="{color: 'red', 'font-size': '40px'}">这是一个善良的H1</h1>
2 . Define the style object into data and directly reference it to: style
Define the style on data:
data: { h1StyleObj: { color: 'red', 'font-size': '40px', 'font-weight': '200' } }
In the element, apply the style object to the element through attribute binding:
<h1 :style="h1StyleObj">这是一个善良的H1</h1>
3. In :style, reference multiple data through an array The style object
defines the style on data:
data: { h1StyleObj: { color: 'red', 'font-size': '40px', 'font-weight': '200' }, h1StyleObj2: { fontStyle: 'italic' } }
In the element, in the form of attribute binding , apply the style object to the element:
<h1 :style="[h1StyleObj, h1StyleObj2]">这是一个善良的H1</h1>
Related recommendations:
Example of VUE component: How does the VUE component implement countdown?
Detailed analysis of threads and processes in Node.js
The above is the detailed content of A brief introduction to several styles used in Vue (with code). For more information, please follow other related articles on the PHP Chinese website!