Mobx 属性 作为函数而不是值返回
Mobx property returned as function instead of value
全名 getter returns 作为函数而不是值。
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"
自动推理已被删除。您需要明确 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;
}
});
全名 getter returns 作为函数而不是值。
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"
自动推理已被删除。您需要明确 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;
}
});