<template>
<div>{{ testWatch }}</div>
</template>
<script>
export default {
data() {
return {
testWatch: 'old string',
testWatch1: {
a: 'old string'
}
};
},
watch: {
testWatch: function (val, oldVal) {
console.log('testWatch: %s, old: %s', val, oldVal)
},
testWatch: 'someMethod'
testWatch: {
handler: function (val, oldVal) {
console.log('testWatch: %s, old: %s', val, oldVal)
},
immediate: true
},
'testWatch1.a': {
handler: function (val, oldVal) {
console.log('testWatch.a: %s, old: %s', val, oldVal)
},
deep: true
},
testWatch: [
'someMethod',
function handle2(val, oldVal) {
},
{
handler: function handle3(val, oldVal) {
}
}
]
},
mounted() {
setInterval(() => {
this.testWatch = 'new string';
this.testWatch1.a = 'new string----';
}, 4000);
},
methods: {
someMethod(n, o) {
console.log('someMethod', n, o);
}
}
};
</script>