반응형
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://unpkg.com/vuex"></script>
    </head>
    <body>
        <style>
            /* Hide un-compiled mustache bindings
            until the Vue instance is ready */
 
            [v-cloak] {
            display: none;
            }
 
            *{
                margin:0;
                padding:0;
            }
 
            body{
                font:15px/1.'Open Sans', sans-serif;
                color: #5e5b64;
                text-align:center;
            }
 
            a, a:visited {
                outline:none;
                color:#389dc1;
            }
 
            a:hover{
                text-decoration:none;
            }
 
            section, footer, header, aside, nav{
                display: block;
            }
 
            /*-------------------------
                The order form
            --------------------------*/
 
            form{
                background-color: #61a1bc;
                border-radius: 2px;
                box-shadow: 1px 1px #ccc;
                width: 400px;
                padding: 35px 60px;
                margin: 50px auto;
            }
 
            form h1{
                color:#fff;
                font-size:64px;
                font-weight: normal;
                line-height:1;
                text-shadow:3px rgba(0,0,0,0.1);
            }
 
            form ul{
                list-style:none;
                color:#fff;
                font-size:20px;
                font-weight:bold;
                text-align: left;
                margin:20px 15px;
            }
 
            form ul li{
                padding:20px 30px;
                background-color:#e35885;
                margin-bottom:8px;
                box-shadow:1px 1px rgba(0,0,0,0.1);
                cursor:pointer;
            }
 
            form ul li span{
                float:right;
            }
 
            form ul li.active{
                background-color:#8ec16d;
            }
 
            div.total{
                border-top:1px solid rgba(255,255,255,0.5);
                padding:15px 30px;
                font-size:20px;
                font-weight:bold;
                text-align: left;
                color:#fff;
            }
 
            div.total span{
                float:right;
            }
        </style>
 
        <form id="app1" v-cloak>
            <h1> Services </h1>
 
            <ul>
                <li v-for="i in list" v-on:click="toggleActive(i)" v-bind:class="{'active' : i.active}">
                    {{i.name}} <span> {{i.price}}</span>
                </li>
            </ul>
            <div class="total">
               Total :: <span> {{ total | currency }}</span>
            </div>
        </form>
 
        <script>
            var vm = new Vue({
                el:"#app1",
 
                created:function(){
                    var ret = 0;
                    for(var i = 0; i < this.list.length; i++){
                        ret += this.list[i].active ? Number(this.list[i].price) : Number(0);
                    }
 
                    this.total = ret;
                },
                data:{
                    list:[
                        {
                            name:'Web Development',
                            price:'300',
                            active:true,
                        },
                        {
                            name:'Design',
                            price:'400',
                            active:true,
                        },
                        {
                            name:'Intergration',
                            price:'250',
                            active:false,
                        },
                        {
                            name:'Training',
                            price:'220',
                            active:false,
                        },
                        {
                            name:'Cooking',
                            price:'1000',
                            active:false,
                        },
                    ],
                    total : 0
                },
 
                methods:{
                    toggleActive: function(val){
                        val.active = !val.active;
 
                        val.active ? this.total += Number(val.price) : this.total -= Number(val.price);
                    },
                },
 
                filters:{
                    currency:function(value){
                        return '$' + value.toFixed(2);
                    }
                }
 
            });
        </script>
    </body>
</html>
cs



css를 떠나서 이전 게시물들을 통해 뷰를 공부했다면 코드를 이해하고 이러한 프로그래밍을 한번 따라해보거나 직접 해보는 것을 추천한다.


css를 빼면 사실상 코드는 60줄 정도 밖에 되지 않는다.



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://unpkg.com/vuex"></script>
    </head>
    <style>
        *{
             margin:0;
            padding:0;
        }
 
        body{
            font:15px/1.'Open Sans', sans-serif;
            color: #5e5b64;
            text-align:center;
        }
 
        a, a:visited {
            outline:none;
            color:#389dc1;
        }
 
        a:hover{
            text-decoration:none;
        }
 
        section, footer, header, aside, nav{
            display: block;
        }
 
        /*-------------------------
            The menu
        --------------------------*/
 
        nav{
            display:inline-block;
            margin:60px auto 45px;
            background-color:#5597b4;
            box-shadow:1px 1px #ccc;
            border-radius:2px;
        }
 
        nav a{
            display:inline-block;
            padding: 18px 30px;
            color:#fff !important;
            font-weight:bold;
            font-size:16px;
            text-decoration:none !important;
            line-height:1;
            text-transform: uppercase;
            background-color:transparent;
 
            -webkit-transition:background-color 0.25s;
            -moz-transition:background-color 0.25s;
            transition:background-color 0.25s;
        }
 
        nav a:first-child{
            border-radius:2px 2px;
        }
 
        nav a:last-child{
            border-radius:2px 2px 0;
        }
 
        nav.home .home,
        nav.projects .projects,
        nav.services .services,
        nav.contact .contact{
            background-color:#e35885;
        }
 
        p{
            font-size:22px;
            font-weight:bold;
            color:#7d9098;
        }
 
        p b{
            color:#ffffff;
            display:inline-block;
            padding:5px 10px;
            background-color:#c4d7e0;
            border-radius:2px;
            text-transform:uppercase;
            font-size:18px;
        }
    </style>
    <body>
        <div id="app">
 
            <nav v-bind:class="active" v-on:click.prevent>
                <a href="#" class="home" @click="makeActive('home')">home</a>
                <a href="#" class="projects" @click="makeActive('projects')">Projects</a>
                <a href="#" class="services" @click="makeActive('services')">services</a>
                <a href="#" class="contact" @click="makeActive('contact')">contact</a>
            </nav>
 
            <p>You chose <b> {{active}} </b> </p>
        </div>
 
        <script>
            var vm = new Vue({
                el:'#app',
 
                data:{
                    active:'home',
                },
 
                methods:{
                    makeActive:function(val){
                        this.active = val;
                    }
                }
            });
        </script>
    </body>
</html>
cs




사실상 이러한 코드를 보면 Vue도 간편하게 해준 것에 대한 장점이 막강하긴 하지만 CSS로 인해 보여지는 시각적 효과가 엄청나고 무시할 수 없을 듯 하다.







반응형

'Basic > VueJS' 카테고리의 다른 글

vue에서 id를 이용한 바인딩  (0) 2018.09.03
Vue에서 style 바인딩 예제  (0) 2018.08.24
[VueJS] vuex 이용 예제  (0) 2018.08.11
[VueJS] 사용자 이벤트  (0) 2018.08.09
[VueJS] 컴포넌트, Props, 상위 하위 컴포넌트  (0) 2018.08.07