全名getter作为函数而不是value返回。
var person = mobx.observable({
firstName: 'Matt',
lastName: 'Ruby',
age: 0,
fullname: function() {
return this.firstName + ' ' + this.lastName
}
});
console.log(person.fullname) // returns a function instead "Matt Ruby"
答案 0 :(得分:0)
已删除自动推理。您需要明确tag the function as a computed:
var person = mobx.observable({
firstName: 'Matt',
lastName: 'Ruby',
age: 0,
fullname: mobx.computed(function() {
return this.firstName + ' ' + this.lastName;
})
});
或者:
var person = mobx.observable({
firstName: 'Matt',
lastName: 'Ruby',
age: 0,
get fullname() {
return this.firstName + ' ' + this.lastName;
}
});