<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
{{ a }}
</div>
<script src="vue.js"></script>
<script>
//el element 缩写 指定vue管理的试图,某个盒子的选择器
//data vue中对象

var data = {a: 1}

const vm = new Vue({el: "#app", data: data});
vm.$data.a = "5";
vm.$watch('a', function (newVal, oldVal) {
console.log(newVal, oldVal)
});
vm.$data.a = "6.................";

</script>
</body>

</html>

vue watch 监听数据变化_javascript