共计 547 个字符,预计需要花费 2 分钟才能阅读完成。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input v-model="info.hobby">
<p> {{info}} </p>
<input v-model="name">
<p> {{name}} </p>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
name: 'tao',
info: {hobby: 'reading',}
},
watch: {name(newV, oldV) {console.log('name', newV, oldV)
},
// info(newV, oldV) {// console.log('info', newV, oldV)
// },
// 深度监听对象
info: {handler: function(newV, oldV) {
// 新老值援用的是同一个对象
console.log('info', newV, oldV)
},
deep: true,
}
}
})
</script>
</html>
正文完