我可以访问旧的属性与新的属性在javascript或vue?



我创建了新的属性名称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);

相关内容

  • 没有找到相关文章

最新更新