Vue.js 我需要知道如何在vuejs中循环一个数组

Vue.js 我需要知道如何在vuejs中循环一个数组,vue.js,foreach,Vue.js,Foreach,我想用vuejs创建一个方法,该方法循环遍历一个对象数组,并给出该数组中的所有名称,但我不知道如何实现 方法如下所示: fruits =[ {name: "apple", calories: "50"}, {name: "apple", calories: "100"}, ]; methode(){ var names = '' foreach(fruit in this.fruits){ names = names+friut.name } return na

我想用vuejs创建一个方法,该方法循环遍历一个对象数组,并给出该数组中的所有名称,但我不知道如何实现

方法如下所示:

fruits =[
  {name: "apple", calories: "50"},
  {name: "apple", calories: "100"},
];
methode(){
  var names = ''
  foreach(fruit in this.fruits){
     names = names+friut.name
  }
  return names
}
水果=[
{名称:“苹果”,卡路里:“50”},
{名称:“苹果”,卡路里:“100”},
];
getNameList(){
返回此.fruits.map(fruit=>fruit.name)

}
不可能重复它不是同一个案例,但它会给我这样的结果[“apple”,“tag apple”]但我想要这样的结果:apple,apple不在阵列中,只需在最后添加一个
.toString()
getNameList(){返回this.fruit.map(fruit=>fruit.name).toString()}
它工作得很好,但是在控制台中它给了我这个错误类型error:Cannot read property'map'of undefined“错误消息说明了一切,你正在向这个函数发送一个未定义的对象。请仔细检查你的数组。