<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<div id="app">
{{ message }}
<button @click="changeMessage">클릭</button><br>
{{ text }}
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'watch는 값을 감시합니다.',
text: ''
},
methods: {
changeMessage() {
this.message = '변경된 값 입니다.';
}
},
watch: {
message(newVal, oldVal) {
this.text = '이전 : ' + oldVal + ' 현재 : ' + newVal;
}
}
})
</script>
'Framework > Vue2' 카테고리의 다른 글
[ Vue2 ] 08. Vue 토글 처리 (0) | 2024.11.08 |
---|---|
[ Vue2 ] 07. Vue 클래스 & 스타일 바인딩 (0) | 2024.11.08 |
[ Vue2 ] 05. Vue Computed 속성 (0) | 2024.11.08 |
[ Vue2 ] 04. Vue 데이터 양방향 바인딩 (0) | 2024.11.08 |
[ Vue2 ] 03. Vue 이벤트 핸들링 (0) | 2024.11.06 |