위와 같이 클릭시 폰트색상을 red로 변경하고 text에 bold를 주었다.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.2/dist/vue.js"></script>
    <title>Document</title>
    <style>
        .red{
            color:red;
        }
        .bold{
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div id="app">
        <div :class="{ red:isRed, blod:isBold }">Hello</div>
        <button @click="update">Click</button>
    </div>
 
    <script>
        new Vue ({
            el: '#app',
            data :{
                message: 'Hello World',
                isRed : false,
                isBold : false
            },
            methods:{
                update(){
                    this.isRed = !this.isRed;
                    this.isBold = !this.isBold;
                }
            }
        });
    </script>
</body>
</html>
cs




'Vue' 카테고리의 다른 글

v-if, v-show 버튼클릭시 보이게 안보이게  (0) 2020.02.15
스타일 바인딩  (0) 2020.02.15
바인딩 양방향바인딩  (0) 2020.02.10
컴포넌트 불러오기  (0) 2019.08.27
vue cli 프로젝트 생성하기 2.X, 3.X  (0) 2019.08.02

+ Recent posts