赞
踩
<template> <div class="hello"> <button @click="change1">改变msg</button> <h1>{{msg}}</h1> <hr> <button @click="change2">改变obj</button> <h2>{{obj.a}}</h2> </div> </template> <script> export default { name: 'HelloWorld', data () { return { msg: 'hello', obj: { a: '123' } } }, methods: { change1 () { this.msg = 'world' }, change2 () { this.obj.a = '456' } }, } </script>
watch: {
msg (newVal, oldVal) {
console.log('new:' + newVal);
console.log('old:' + oldVal);
}
}
watch: {
obj: {
handler (newVal, oldVal) {
console.log('watch1');
console.log('new:' + newVal);
console.log('old:' + oldVal);
},
// deep: true
}
}
watch: {
obj: {
handler (newVal, oldVal) {
console.log('watch1');
console.log('new:' + newVal.a);
console.log('old:' + oldVal.a);
},
deep: true
}
}
watch: {
'obj.a': {
handler (newVal, oldVal) {
console.log('watch2');
console.log('newVal:' + newVal);
console.log('oldVal:' + oldVal);
},
// deep: true
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。