watch属性
<body> <div id="app"> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> const app = new Vue({ el:'#app', data:{ message:'hello world' }, watch:{ message(newValue,oldValue){ //监听message值变化 console.log("新的值:",newValue); console.log("旧的值:",oldValue); } } }) </script> </body>