Home Web Front-end JS Tutorial How to set up multiple Classes using Vue

How to set up multiple Classes using Vue

Jun 12, 2018 pm 08:23 PM
vue binding

This article mainly introduces the example code of using Vue to bind single or multiple Class names. It is very good and has reference value. Friends who need it can refer to it

一, Bind a single Class name in the form of a variable

Binding a single class name in vue is easy, just write it directly

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

<template>

 <p id="app">

 <!-- 因为是自定义属性,所以要用到 v-bind ,简写为 : -->

 <!-- 3.将 box 绑定给 p -->

 <p :class="box"></p>

 </p>

</template>

 

<script>

export default {

 name: 'app',

 data () {

 return {

 // 2.在 data 中把 yellow 赋给 box

 box: 'yellow'

 }

 }

}

</script>

 

<style>

/* 1.在样式表中写好样式 */

.yellow{

 width: 200px;

 height: 200px;

 background: #ff0;

}

</style>

Copy after login

Use Vue to bind a single Class name

2. Bind multiple Class names in array form

For example, if we want to give Add a shadow to this p

Write the style in style

1

2

3

.shadow{

 box-shadow: 10px 10px 5px 0 #999;

}

Copy after login

Continue to add data objects in data

1

2

3

4

5

6

7

8

9

10

11

<script>

export default {

 name: 'app',

 data () {

 return {

 box: 'yellow',

 shadow:'shadow'

 }

 }

}

</script>

Copy after login

Bind the Class name in the form of an array in the tag

1

2

3

4

5

<template>

 <p id="app">

 <p :class="[box,shadow]"></p>

 </p>

</template>

Copy after login

It’s OK.

Bind multiple Class names in array form

3. Bind multiple Class names in json form

This method is convenient for determining which style to display when adding multiple Class names at the same time.

Write the style first

1

2

3

4

5

6

7

8

9

10

<style>

.yellow{

 width: 200px;

 height: 200px;

 background: #ff0;

}

.shadow{

 box-shadow: 10px 10px 5px 0 #999;

}

</style>

Copy after login

Add a digital object to the data for judgment

1

2

3

4

5

6

7

8

9

10

11

<script>

export default {

 name: 'app',

 data () {

 return {

 show1:true,

 show2:false

 }

 }

}

</script>

Copy after login

Bind it to the class in the form of json, and change the values ​​of show1 and show2 through Boolean values ​​to control the status of p

1

2

3

4

5

<template>

 <p id="app">

 <p :class="{yellow:show1,shadow:show2}"></p>

 </p>

</template>

Copy after login

Use json form to bind multiple Classes

ps: vue solves cross-domain problems

Change config /index.js file

1

2

3

4

5

6

7

8

proxyTable: {

// 请求到 '/device' 下 的请求都会被代理到 target: http://debug.xxx.com 中

'/v1/*': {

target: 'https://api.tiaotiao5.com',

secure: true, // 接受 运行在 https 上的服务

changeOrigin: true

}

}

Copy after login

The above is all the content I summarized, I hope it will be helpful to everyone

Related articles:

How to implement multiplexing in JavaScript Inherit

About how Wangwang online customer service implements

How to implement web mouse special effects (detailed tutorial)

The above is the detailed content of How to set up multiple Classes using Vue. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use echarts in vue How to use echarts in vue May 09, 2024 pm 04:24 PM

How to use echarts in vue

The role of export default in vue The role of export default in vue May 09, 2024 pm 06:48 PM

The role of export default in vue

How to use map function in vue How to use map function in vue May 09, 2024 pm 06:54 PM

How to use map function in vue

The difference between event and $event in vue The difference between event and $event in vue May 08, 2024 pm 04:42 PM

The difference between event and $event in vue

The role of onmounted in vue The role of onmounted in vue May 09, 2024 pm 02:51 PM

The role of onmounted in vue

The difference between export and export default in vue The difference between export and export default in vue May 08, 2024 pm 05:27 PM

The difference between export and export default in vue

Onmounted in vue corresponds to which life cycle of react Onmounted in vue corresponds to which life cycle of react May 09, 2024 pm 01:42 PM

Onmounted in vue corresponds to which life cycle of react

What are hooks in vue What are hooks in vue May 09, 2024 pm 06:33 PM

What are hooks in vue

See all articles