Vue는 :class와 :style에 특수한 객체 및 배열 문법을 제공하여, 반응형 상태에 따라 클래스와 인라인 스타일을 조건부로 적용할 수 있습니다 — 클래스 문자열을 수동으로 만드는 것보다 깔끔합니다.
:class의 객체 문법 — 조건으로 클래스 토글
vue
<script setup>
import { ref } from "vue";
const isActive = ref(true);
const hasError = ref(false);
</script>
<template>
<!-- 값이 truthy일 때 클래스가 적용됨 -->
<div :class="{ active: isActive, 'text-red': hasError }">...</div>
<!-- class="active"로 렌더링 (active=true, text-red=false) -->
</template>
