Home > Web Front-end > JS Tutorial > A brief introduction to several styles used in Vue (with code)

A brief introduction to several styles used in Vue (with code)

不言
Release: 2018-08-09 17:50:08
Original
1715 people have browsed it

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.

Use class style

1. Array

  <h1 :class="[&#39;red&#39;, &#39;thin&#39;]">这是一个邪恶的H1</h1>
Copy after login

2. Use ternary expression in array

  <h1 :class="[&#39;red&#39;, &#39;thin&#39;, isactive?&#39;active&#39;:&#39;&#39;]">这是一个邪恶的H1</h1>
Copy after login

3. Nested objects in array

  <h1 :class="[&#39;red&#39;, &#39;thin&#39;, {&#39;active&#39;: isactive}]">这是一个邪恶的H1</h1>
Copy after login

4. Use the object directly

  <h1 :class="{red:true, italic:true, active:true, thin:true}">这是一个邪恶的H1</h1>
Copy after login

Use inline style

1. Write the style object directly on the element in the form of :style

  <h1 :style="{color: &#39;red&#39;, &#39;font-size&#39;: &#39;40px&#39;}">这是一个善良的H1</h1>
Copy after login

2 . Define the style object into data and directly reference it to: style

  • Define the style on data:

 data: {
      h1StyleObj: { color: &#39;red&#39;, &#39;font-size&#39;: &#39;40px&#39;, &#39;font-weight&#39;: &#39;200&#39; }
 }
Copy after login
  • In the element, apply the style object to the element through attribute binding:

 <h1 :style="h1StyleObj">这是一个善良的H1</h1>
Copy after login

3. In :style, reference multiple data through an array The style object

  • defines the style on data:

  data: {
        h1StyleObj: { color: &#39;red&#39;, &#39;font-size&#39;: &#39;40px&#39;, &#39;font-weight&#39;: &#39;200&#39; },
        h1StyleObj2: { fontStyle: &#39;italic&#39; }
  }
Copy after login
  • In the element, in the form of attribute binding , apply the style object to the element:

 <h1 :style="[h1StyleObj, h1StyleObj2]">这是一个善良的H1</h1>
Copy after login

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!

Related labels:
vue
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