<template>
<div>
<p>{{ obj.a }}</p>
<input v-model="obj.a" />
<p>{{ obj.b }}</p>
<input v-model.number="obj.b" />
</div>
</template>
<script>
let unwatch = null
export default {
data () {
return {
obj: {
a: '',
b: 18
}
}
},
mounted () {
unwatch = this.$watch(function () {
return JSON.parse(JSON.stringify(this.obj))
}, function (val, oldVal) {
console.log(val.a, oldVal.a, 'changed')
}, {
deep: true
})
},
beforeDestroy () {
unwatch()
}
}
</script>
网友评论