我想用vuejs制作一个遍历对象数组的方法,并为我提供该数组中的所有名称,但是我不知道怎么做
方法将如下所示:
fruits =[
{name: "apple", calories: "50"},
{name: "apple", calories: "100"},
];
methode(){
var names = ''
foreach(fruit in this.fruits){
names = names+friut.name
}
return names
}
答案 0 :(得分:0)
fruits =[
{name: "apple", calories: "50"},
{name: "apple", calories: "100"},
];
getNameList(){
return this.fruits.map(fruit => fruit.name)
}