我创建了新的属性名称styleTitle,我想得到styleTitle = title + styleTitle。我尝试在vue js中显示结果undefineObject
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
title: "Style",
styleTitle: this.title + "Object",
eyeColor: "blue"
};
如果对象的一个属性基于另一个属性,则考虑使用getter:
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
title: "Style",
eyeColor: "blue",
get styleTitle() {
return this.title + "Object"
},
};
console.log(person.styleTitle);