computed
It is to calculate the property values calculated dependent on other attributes, and computed
values are cached content will return only if the calculated value changes.
watch
Change Listener will callback to a value, some of the logic operations may be performed in a callback.
So in general need to rely on other attributes to dynamically obtain time values can be used computed
for listening to the change in the value needs to do some complicated business logic can be used watch
.
In addition computed
, and watch
also support the wording objects
vm.$watch('obj', {
// depth traversal
deep: true,
// immediately trigger
immediate: true,
// function execution
handler: function(val, oldVal) {}
})
was vm = new Vue ({
data: { a: 1 },
computed: {
aPlus: {
When the trigger // this.aPlus
get: function () {
return this.a + 1
},
// this.aPlus = 1 trigger
set: function (v) {
this.a = v - 1
}
}
}
})