본문 바로가기

Framework/Vue2

[ Vue2 ] 07. Vue 클래스 & 스타일 바인딩

<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
    .alert-msg {
        background: red;
        color: white;
    }
</style>
</head>
<div id="app">
<div :class="{ 'alert-msg': active }">이것은 클래스 바인딩을 이용한 메시지 입니다.</div>
<button @click="changeClass">클릭</button>
<hr/>
<div :style="{ color: color, background: back_color }">이것은 스타일 바인딩을 이용한 메시지 입니다.</div>
<button @click="changeStyle">클릭</button>
</div>
</div>
<script>
new Vue({
    el: '#app',
    data: {
        active: false,
        color: '#FF0000',
        back_color: '#00FF00'
    },
    methods: {
        changeClass() {
            this.active = !this.active;
        },
        changeStyle() {
            let color = this.color
            this.color = this.back_color;
            this.back_color = color;
        }
    }
})
</script>

'Framework > Vue2' 카테고리의 다른 글

[ Vue2 ] 08. Vue 조건문 처리  (0) 2024.11.08
[ Vue2 ] 08. Vue 토글 처리  (0) 2024.11.08
[ Vue2 ] 06. Vue Watch 속성  (0) 2024.11.08
[ Vue2 ] 05. Vue Computed 속성  (0) 2024.11.08
[ Vue2 ] 04. Vue 데이터 양방향 바인딩  (0) 2024.11.08