Vue 를 소개하기 위해서는 Reactivity 가 필수
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<!-- hello world -->
</div>
<script>
var div = document.querySelector('#app');
var str = 'hello world';
div.innerHTML =str;
// --> hello world
str = 'hello world!!!!';
div.innerHTML = str;
// --> hello world
</script>
</body>
</html>
Reactivity 반응성<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script>
var div = document.querySelector('#app');
var viewModel = {};
Object.defineProperty(viewModel,'str',{
//속성에 접근했을 때의 동작을 정의
get : function(){
console.log('접근');
},
//속성에 값을 할당했을때의 동작을 정의
set : function(newValue){
console.log('할당', newValue);
div.innerHTML= newValue;
}
})
</script>
</body>
</html>
object.defineProperty()
객체의 동작을 재정의하는 api 이다.
문법
Object.defineProperty(대상객체,객체의 속성, {
정의할 내용
} );