If I have a computed property that looks like this:
computed: {
greeting() {
const state = this.$store.state;
if (state.name === 'Joe') {
return 'Hey, Joe';
} else {
return 'Hello, ' + state.name;
}
}
}
What object(s) is Vue going to set an observer on? this.$store.state
or state.name
or both? Asking because:
Provided that the this.$store.state
and this.$store.state.name
properties are reactive (they should be), then Vue will observe changes to these properties and re-evaluate greeting
when the values of these properties change.
No other properties will be observed.
This will cause greeting
to be re-evaluated:
this.$store.state.name = 'foo';
this.$store.state = bar();
This will not cause greeting
to be re-evaluated:
this.$store.state.foo = 'foo';
this.$store.state.a.b.c = 'bar';
this.$store.apple = 'pink lady';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.