1. Text Interpolation
2. Raw HTML
3. Attribute Bindings
4. JavaScript Expressions
<p>Message:{{msg}}</p>
Raw HTML
<div v-html='rawHTML'></div>
const rawHTML = ref('<span style='color:red'>This should be red.</span>')
Attribute Bindings
<div v-bind:id='dynamicId'></div>
const dynamicId = ref('my-id)
JavaScript Expressions
1. Attribute Bindings
2. Class and Style Bindings
Attribute Bindings
<img v-bind:src='imageSrc'>
<a v-bind:href='myUrl'>Move to URL</a>
<button :[key]='myValue'></button>
Class and Style Bindings
const isActive = ref(false)
<div :class="{ active: isActive }">Text</div>
const isActive = ref(false)
const hasInfo = ref(true)
<div class="static" :class="{ active: isActive, 'text-primary': hasInfo }">Text</div>
:class를 배열에 바인딩 하여 클래스 목록을 적용할 수 있다.
const activeClass = ref('active')
const infoClass = ref('text-primary')
<div :class="[activeClass, infoClass]">Text</div>
<div :class="[{active: isActive}, infoClass]">TEXT</div>
Binding Inline Styles
- 2.1 Binding to Objects
:style은 JavaScript 객체 값에 대한 바인딩을 지원 (HTML style 속성에 해당)
<div :style="{ 'font-size' : fontSize + 'px'}">Text</div>
const styleObj = ref({
color: activeColor,
fontSize : fontSize.valut + 'px'
})
<div :style='styleObj'>TEXT</div>
const styleObj2 = ref({
color: 'blue',
border: '1px solid black'
})
<div :style="[styleObj, styleObj2]">TEXT</div>
Inline Handlers : 이벤트가 트리거 될때 실행될 javascript 코드
const count = ref(0)
<button @click="count++">ADD 1</button>
<p>Count : {{count}} </p>입력하세요
Method Handlers : 컴포넌트에 정의된 메서드 이름
const name = ref('Alice')
const myFunc = function(event) {
console.log(event)
console.log(event.currentTarget)
console.log(`Hello ${name}.value!`)
<button @click='myFunc'>Hello</button>
const myFunc = function(event) {
console.log(event)
console.log(event.currentTarget)
console.log(`Hello ${name.value}!`)
}
@event = "handler"
const greeting = function(message) {
console.log(message)
}
<button @click='greeting('hello')'>Say Hello</button>
<button @click='greeting('bye')>Say bye</button>
input @keyup.enter='onSubmit'>
form을 처리할 때 사용자가 input에 입력하는 값을 실시간으로 JavaScript 상태에 동기화 해야하는 경우(양방향 바인딩)
방법
- 1. v-bind와 v-on 함께 사용
const inputText1 = ref('')
const onInput = function (event) {
inputText1.value = event.currnetTarget.value
}
<p>{{inputText1}}</p>
<input :value='inputText1' @input='onInput'>
const inputText2 = ref('')
<p>{{inputText2}}</p>
<input v-model='inputText2'>
v-model은 단순한 text input 뿐만 아니라 Checkbox, radio, select 등 다양한 타입의 사용자 입력 방식과 입력방식과 함께 사용가능하다
checkbox 활용
- 1. 단일 체크박스와 boolean 값 활용
const checked = ref(false)
<input type="checkbox" id="checkbox" v-model="checked">
<label for="checkbox">{{ checked }}</label>

- 2. 여러 체크박스와 배열 활용
해당 배열에는 현재 선택된 체크박스의 값이 포함된다.
const checkedNames = ref([])
<div>Checked Names : {{checkedNames}}</div>
<input type='checkbox' id='alice' value= 'Alice' v-model='checkedNames'>
<label for='alice'>Alice</label>
<input type='checkbox' id='bella' value= 'Bella' v-model='checkedNames'>
<label for='bella'>Bella</label>
```
Select 활용
- 2. select에서 v-model 표현식의 초기 값이 어떤 option과도 일치하지 않는 경우 select 요소는 "선택되지 않은(unselected)"상태로 렌더링된다.
const selected = ref('')
<div>Selected: {{ selected }}</div>
<select v-model='selected'>
<option disabeld value = ''>Please select one</option>
<option>Alice</option>
<option>Bella</option>
<option>Cathy</option>
</select>